search

Home  >  Q&A  >  body text

javascript - Use PHP to process the code produced by the rich text editor, replace the href of the a link with title="fish link" to bbb.com

For example:

is replaced with

Seeking solutions.

習慣沉默習慣沉默2788 days ago665

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-24 11:32:47

    preg_replace Regular expression search and replace

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-24 11:32:47

    Using preg_replace, I wrote a simple example:

    
    $b = '
    <a href="http://tool.chinaz.com/" title="fish link">df</a>
    <a href="http://tool.chinaz.com/" title="no match">df</a>
    <a href="http://tool.chinaz.com/" title="fish link">df</a>
    ';
    
    var_dump(preg_replace('/<a.*title="fish link">/', '<a href="http://bbb.com" title="fish link">', $b));

    output:

    string(157) "
    <a href="http://bbb.com" title="fish link">df</a>
    <a href="http://tool.chinaz.com/" title="no match">df</a>
    <a href="http://bbb.com" title="fish link">df</a>
    "

    reply
    0
  • Cancelreply