简体   繁体   中英

Why doesnt this simple dom work?

I am trying to get all the image src's and rename the files using this code but it doesnt seem to work.

Any ideas ??

require_once('catalog/controller/forum/simple_html_dom.php');
$test = $data['description'];
$html = str_get_html($test);
foreach($html->find('img') as $element) {
$src = $element->src;
rename($src,$src.".jms");
}

All images files are local and this is an example image tag.

<img alt="Image" src="image/data/attaches/f7ff31f73f6d41f108ef31c01ea69228.png">

So i'm trying to rename the file from that to the same location but by adding .jms to the end. Also i'm not sure how but i want to modify all the image tags in the string so i can put it back modified with the mysql update command. The string $data['description'] contains other html not just image tags. Its varied.

rename() could only used to the local files in your server, no way to rename the remote files.

If the images are in your server, and you could know the real path from the src , then you need to convert the src to the real path of the image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM