Solution 1 :

This question was already answered




First, make sure the server let you fetch the data.

Second, use a html parser instead to parse the data.

// Gets the webpage
$html = @file_get_contents('');

//if no webpage found die and return an error
if (!$html) {
  die('can not get the content!');

//Create a new DOM Doc
$doc = new DOMDocument();

//Load the HTML of the page you fetch in the DOM Doc

//Get the element with the ID test
$content = $doc->getElementById('test');

Note that if the element is empty, the Dom returns NULL

Don’t use javascript for that.

You can learn more about DOMDocument on the PHP doc:

And here’s more about the getElementById

Problem :

I’m looking how I can get <p id="test"></p> as number in PHP.
I have select option and with code below I get my variation id selected as html paragraph <p id="test"></p> but I need it as number in PHP to run another PHP code to compere something how can I convert <p id="test"></p> to a number in php without using another java script I just need number form my code below as variable number in php.

I’m using woocommerce plugin in WordPress and I need new way of showing images based on user selected option in single product page instead of switching I need to overlay product image with variation images because of that I have user selected option with code below but I need it to work in php I don’t know how to convert <p id="test"></p> this code to php to get number and do my other things I know how to do I just need to get <p id="test"></p> as number in php .


 if ( $product->is_type('variable') ) {

      jQuery(document).ready(function($) {

         $('input.variation_id').change( function(){
            if( '' != $('input.variation_id').val() ) {

               var var_id = $('input.variation_id').val();
               document.getElementById('test').textContent = var_id;




I need to get instead of this <p id="test"></p> a number in php .


Comment posted by PHPnoob

What should this number correspond to ?

Comment posted by vivanred

@PHPnoob I’m using WordPress woocommerce plugin and I need to have another way of showing Images because of I should compere my new way of showing Images based on woocommerce variation selected I have with this code what user selected but I need it as number to compere selected with variation images and my product image to have overlay variation images on product image as frame picture instead of switching image between them instead of woocommerce base way of showing image

Comment posted by PHPnoob

So you have several p elements which each contain an image, and you want to identify the selected one ?

Comment posted by vivanred

@PHPnoob no . I just have one and need it to convert to php as number variable . and then based on number bring products variation name and image . because I need user selected option for know what user wants for show . I just wnat have image product overlay by variation images based on user selected .