Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP更改图像位置_Php_Image_Content Management System - Fatal编程技术网

PHP更改图像位置

PHP更改图像位置,php,image,content-management-system,Php,Image,Content Management System,我使用的是一个旧的内容管理系统,它使用CKEditor和CKFinder,允许您将图像上传到服务器,但是它会将完整的URL放入内容框中,然后我将其保存到数据库中 我最近重建了我的内容管理系统,并再次使用CKEditor和CKFinder。我目前正在移动数据库并重新排列数据。但是我注意到这些图片的URL是错误的 所以我的问题是,是否可以搜索和替换URL,并且每个字符串可以搜索多次?中间也有一个随机的散列键,我不太确定如何绕过,这就是为什么我问这个问题。 URL将为(未编辑) 我想提取url并将其路

我使用的是一个旧的内容管理系统,它使用CKEditor和CKFinder,允许您将图像上传到服务器,但是它会将完整的URL放入内容框中,然后我将其保存到数据库中

我最近重建了我的内容管理系统,并再次使用CKEditor和CKFinder。我目前正在移动数据库并重新排列数据。但是我注意到这些图片的URL是错误的

所以我的问题是,是否可以搜索和替换URL,并且每个字符串可以搜索多次?中间也有一个随机的散列键,我不太确定如何绕过,这就是为什么我问这个问题。 URL将为(未编辑)

我想提取url并将其路径更改为:

http://www.newwebsite.com/images/uploaded/image.jpg
我不知道我将如何开始和结束,而跳过了中间部分。或者可以只在末尾获取image.jpg,我将在开始时输入新路径

到目前为止,我只有两行代码,但请记住这是HTML

$content = '<h1>'.$page['Page_Title'].'</h1>';
$content .= $page['Page_Content'];  

我不知道你的桌子是什么结构。您可以在旧数据库上运行如下所示的mysql查询来更新路径。如果这对你没有帮助,发布你的表格结构,我很乐意更新我的答案

sql=" UPDATE page SET page_content = REPLACE(page_content, 'http://www.oldwebsite.com/aknsnd8123nakndkna/upload/images/', 'http://www.newwebsite.com/images/uploaded/')";

希望对你有所帮助。

我找到了方法!感谢阿尔瓦罗·冈萨雷斯的建议

    $content = '<h1>'.$page['Page_Title'].'</h1>';
    $content .= $page['Page_Content'];  
    $html = new DOMDocument(); 
    $html->loadHTML($content);  
    foreach ($html->getElementsByTagName('img') as $image) {
        $img = array_reverse(explode('/', $image->getAttribute('src')));
        $image->setAttribute('src', $website.'/images/uploaded/'.$img[0]);
    }
    $content = $html->saveHTML();
$content='.$page['page_Title'.];
$content.=$page['page_content'];
$html=新的DOMDocument();
$html->loadHTML($content);
foreach($html->getElementsByTagName('img')作为$image){
$img=array_reverse(分解('/',$image->getAttribute('src'));
$image->setAttribute('src',$website'./images/upload/'.$img[0]);
}
$content=$html->saveHTML();

您没有提供太多信息。。。是否要编写迁移脚本来更改某种数据库或存储系统中的数据?我正在编写迁移脚本,从旧数据库中提取数据,重新排列,然后将其插入新数据库。我请求帮助的是在重新排列部分,在我将其发送到新数据库之前。因为其他一切似乎都很清楚。。。你需要找到一个PHP库来连接到你的数据库(PDO有几个引擎的驱动程序),使用DOMDocument或类似的解析器从HTML中提取链接,并组成一个正则表达式来处理实际的替换。我尝试了你用DOMDocument所说的,看到我的答案了吗?谢谢你的建议!根据我编辑的问题,
Page\u Content
列包含HTML。这样行吗?即使该行包含HTML?@Sickaaron,您的表名是什么,我猜是“页面”。如果是,我已经更新了查询。希望这有帮助。
sql=" UPDATE page SET page_content = REPLACE(page_content, 'http://www.oldwebsite.com/aknsnd8123nakndkna/upload/images/', 'http://www.newwebsite.com/images/uploaded/')";
    $content = '<h1>'.$page['Page_Title'].'</h1>';
    $content .= $page['Page_Content'];  
    $html = new DOMDocument(); 
    $html->loadHTML($content);  
    foreach ($html->getElementsByTagName('img') as $image) {
        $img = array_reverse(explode('/', $image->getAttribute('src')));
        $image->setAttribute('src', $website.'/images/uploaded/'.$img[0]);
    }
    $content = $html->saveHTML();