PHP 现在要实现内链功能, 替换关键词为 a标签, 但是alt中也会有关键词 替换后就会导致出错,
我想把alt中的关键词替换成其他字符在完成内链后在替换回来
$newsinfo[content]=preg_replace("/(?<=alt=\".*)(格斗江湖)(?=.*\")/","&&&&%%%%","<img alt=\"113453451格斗江湖56546456546\"");
php 的 (?cc3b869d92f226db8505ba9d98d8eb46');
echo preg_replace('/alt=".+?(格斗江湖).+?"/',"&&&&%%%%",'b611f7c13d91e757834972cc675b54e7');
php 的 (?<=pattern) 断言 是定长的
而你些的是不定长的 (?<=alt=\" .*)
echo preg_replace('/alt="(.+?)(格斗江湖)(.+?)"/','alt="$1&&&&%%%%$3"','b611f7c13d91e757834972cc675b54e7');
$html = '<img alt="113453451格斗江湖56546456546">格斗江湖';echo preg_replace('#(?=[^>]*(?=<(?!/a>)|$))格斗江湖#','<a href="新加的链接.html">\0</a>',$html);b611f7c13d91e757834972cc675b54e7be5d6083c662afdb9928d850f8afed38格斗江湖5db79b134e9f6b82c0b36e0489ee08ed
echo preg_replace('/alt="(.+?)(格斗江湖)(.+?)"/','alt="$1&&&&%%%%$3"','b611f7c13d91e757834972cc675b54e7');
$html = '<img alt="113453451格斗江湖56546456546">格斗江湖';echo preg_replace('#(?=[^>]*(?=<(?!/a>)|$))格斗江湖#','<a href="新加的链接.html">\0</a>',$html);b611f7c13d91e757834972cc675b54e7be5d6083c662afdb9928d850f8afed38格斗江湖5db79b134e9f6b82c0b36e0489ee08ed
手册中有,不过是英文的
网上一些教程中也提及到
The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length.
一个追溯断言的内容限制,所有的字符串匹配的必须有一个固定的长度