简体   繁体   English

为什么这个简单的dom不起作用?

[英]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. 我正在尝试获取所有图像src并使用此代码重命名文件,但它似乎不起作用。

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. 因此,我尝试将文件从该文件重命名到相同的位置,但要在末尾添加.jms。 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. 另外我不确定如何,但是我想修改字符串中的所有图像标签,以便我可以用mysql update命令将其修改回来。 The string $data['description'] contains other html not just image tags. 字符串$ data ['description']包含其他html,而不仅仅是图像标签。 Its varied. 它多种多样。

rename() could only used to the local files in your server, no way to rename the remote files. rename()仅用于服务器中的本地文件,无法重命名远程文件。

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. 如果图像在您的服务器中,并且您可以从src知道真实路径,则需要将src转换为图像的真实路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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