Viewed   66 times

I have a div in php(string) and I want to get the content.

for example:

<div id="product_list" style="width:100%; float:none;">
      <div>
       bla bla bla
      </div>
      bla bla          
</div>

and I want

<div>
     bla bla bla
</div>
     bla bla

The style is changing, I know only the div id.

UPDATED

this is my code, same as turbod source and the results are the same too.

so this is the original html

$doc = new DOMDocument();
$doc->loadHTML($buffer);
$id = $doc->getElementById('product_list')

And after this code I get the following: link

 Answers

5

Use the php DomDocument class. http://www.php.net/manual/en/class.domdocument.php

$dom = new DOMDocument();

$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$divContent = $xpath->query('//div[id="product_list"]');
Sunday, October 16, 2022
5

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)

Options:
  ...
  -r, --register-only
        do not remove files, only register the packages as not installed
  ...

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Monday, December 12, 2022
1

I'm Not Experience Developer so i just try This Code can fetch only first image

<?php
$url = 'http://.com/questions/7994340/how-can-i-get-image-from-url-in-php-or-jquery-or-in-both';
$data = file_get_contents($url);

if(strpos($data,"<img"))
{
    $imgpart1 = explode('<img src=',$data);
    $imgpart2 = explode('"',$imgpart1[1]);
    echo "<img src=".$imgpart2[1]." />";
}
?>
Sunday, August 21, 2022
4
$currentMonth = date('F');
echo Date('F', strtotime($currentMonth . " last month"));

If you don't want it relative to the current month then set:

$currentMonth = 'February';
// outputs January
Wednesday, November 2, 2022
 
farhad
 
4

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, November 11, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :