当前位置: 动力学知识库 > 问答 > 编程问答 >

preg replace - Multi-line Links with preg_replace | PHP

问题描述:

If someone posts a multi-line post that contained text and links, I want to be able to find and wrap the links with <p> tags, but I can only do it with one link at a time (source code comes from phpBB2 - clickable links function), which causes every link to be like this:

<p>http://www.bbc.co.uk/</p>

<p>http://www.bbc.co.uk/</p>

<p>http://www.bbc.co.uk/</p>

Where I want it to happen to be like this:

<p>http://www.bbc.co.uk/

http://www.bbc.co.uk/

http://www.bbc.co.uk/</p>

Cheers.

网友答案:

Feed it to DOM loadHTML function and getElementsByTagName('p'), make a reference with ->item(i) based on the ->length, get the nodeValue and just make a new paragraph with document.createElement, set the nodeValue to your string of nodeValues that you retrieved from the loop after concatenating them with \n<br> or something.

You shouldn't use regex for this.

分享给朋友:
您可能感兴趣的文章:
随机阅读: