php正则表达式匹配出想要的结果

毕设客栈 其他问答 1

如何写才能把

  第一集#https://iqiyi.cdn9-okzy.com/20201104/43645634255.html
  第二集#https://iqiyi.cdn9-okzy.com/20201104/75676457567.html

正则匹配出#的前后生成

<a src="https://iqiyi.cdn9-okzy.com/20201104/43645634255.html">第一集</a>
<a src="https://iqiyi.cdn9-okzy.com/20201104/75676457567.html">第二集</a>

类似

 $content = preg_replace("第一集#https://iqiyi.cdn9-okzy.com/20201104/43645634255.html", '<a src="$1">$2</a>\n', $content);

昨天试了一天没成功

回复

共2条回复 我来回复
  • 代码小屋
    这个人很懒,什么都没有留下~
    评论
        $content="第一集#https://iqiyi.cdn9-okzy.com/20201104/43645634255.html
    
       第二集#https://iqiyi.cdn9-okzy.com/20201104/75676457567.html";
    echo $content = preg_replace("/(.*?)\#(.*?)/iU", '<a src="$2">$1</a><br>', $content);
    
    0条评论
  • 毕设海岸
    这个人很懒,什么都没有留下~
    评论
    $content= "第一集#https://iqiyi.cdn9-okzy.com/20201104/43645634255.html"
    $content = preg_replace("(.*)#(.*)","<a src='$2'>$1</a><br>",$content);
    
    0条评论

发表回复

登录后才能评论