Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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纠正TinyMCE URL转换_Php_Tinymce - Fatal编程技术网

PHP纠正TinyMCE URL转换

PHP纠正TinyMCE URL转换,php,tinymce,Php,Tinymce,TinyMCE用于自定义CMS,将URL中的符号和转换为html实体,如下所示: <img src="https://maps.googleapis.com/maps/api/staticmap?markers=15.44,-14.57&amp;zoom=14&amp;size=250x180&amp;sensor=false" alt="map" /> 此图像导致错误“Google Maps API服务器拒绝了您的请求。请求无效。缺少'size'参数。

TinyMCE用于自定义CMS,将URL中的符号和转换为html实体,如下所示:

<img src="https://maps.googleapis.com/maps/api/staticmap?markers=15.44,-14.57&amp;zoom=14&amp;size=250x180&amp;sensor=false" alt="map" />

此图像导致错误“Google Maps API服务器拒绝了您的请求。请求无效。缺少'size'参数。”

我无法改变TinyMCE的行为(没有任何效果)

或者,我想在保存到DB之前使用PHP查找replace all href/src

如何在PHP中编写代码,在字符串$post中搜索href/src URL,并找到符号和html实体代码,并将其替换为“&”


我尝试了使用preg_replace的示例,但无法使其正常工作。

我使其正常工作,希望它能帮助他人

$str = '<a href="https://some.com/?m=1&amp;z=2&amp;s=3&amp;r=f">some text</a><img src="https://maps.googleapis.com/maps/api/staticmap?markers=136.22,-186.74&amp;zoom=14&amp;size=250x180&amp;sensor=false" alt="map" />';

$re = '/(href|src)=("[^"]*")/'; 
preg_match_all($re, $str, $matches);
foreach ($matches[0] as $match){
    $conv = str_replace('&amp;', '&', $match);
    $str = str_replace($match, $conv, $str);
}

echo $str; // &amp; in url converted to &
$str='';
$re='/(href | src)=(“[^”]*”)/;
预匹配全部($re,$str,$MATCHS);
foreach($matches[0]为$match){
$conv=str_replace(“&;”、“&;”、$match);
$str=str\u replace($match,$conv,$str);
}
将url中的echo$str;//&;转换为&

Tinymce有时会因为旧版本的PHP而出现问题。我在安装上一个版本的PHP时解决了很多问题。