How can I solve the problem of automatically adding link to the URL and ubb code conflict?

Source: Internet
Author: User
How can I solve the problem of automatically adding link to the URL and ubb code conflict? Preg_replace ("# (mms | http | https | ftp | telnet) (: //) [.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) # I "," \ 1 ", $ text );

The above section automatically adds links to the URLs in a text segment, but some ubb code links cannot automatically add links. how can we eliminate them? Because ubb is automatically converted to a link.
Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase
How can I exclude that links in tags such as [url] or [img] should not be automatically added? Or is there any other regular expression that can be done?
Thank you!


Reply to discussion (solution)

Such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb]

Or I want to convert the ubb code and add links to the URLs that are not wrapped up by the ubb code. how can this problem be solved?

Try
Preg_replace ("#(?

$ Text = <TXT automatically adds links to the URLs in a text section, but some ubb code links cannot automatically add links. how can this problem be ruled out? Because ubb is automatically converted to a link. Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb] TXT; echo preg_replace ("# ([^]) (mms | http | https | ftp | telnet )(://)[.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) (?> = 【)? # Isu "," $1 $2 ", $ text );
The above section automatically adds links to the URLs in a text segment, but some ubb code links cannot automatically add links. how can we eliminate them? Because ubb is automatically converted to a link.
Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase target = _ blank> http://bbs.csdn.net/topics/new? Forum_id = PHPBase </a>
Such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb]

Try
Preg_replace ("#(?
It seems yes, but it is not the [ubb \] tag. The first-floor error should be [img] and [url] tags. you can replace [ubb \] with [url \], but only one tag can be excluded. how can I exclude multiple tags? To exclude [img \]

$ Text = <TXT automatically adds links to the URLs in a text section, but some ubb code links cannot automatically add links. how can this problem be ruled out? Because ubb is automatically converted to a link. Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb] TXT; echo preg_replace ("# ([^]) (mms | http | https | ftp | telnet )(://)[.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) (?> = 【)? # Isu "," $1 $2 ", $ text );
The above section automatically adds links to the URLs in a text segment, but some ubb code links cannot automatically add links. how can we eliminate them? Because ubb is automatically converted to a link.
Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase target = _ blank> http://bbs.csdn.net/topics/new? Forum_id = PHPBase </a>
Such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb]

====
This [] number is actually [] this number, because it will be automatically converted into a link here when it is written as [], so it is written 【]

You just need to change it?

$ Text = <TXT automatically adds links to the URLs in a text section, but some ubb code links cannot automatically add links. how can this problem be ruled out? Because ubb is automatically converted to a link. Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb] TXT; echo preg_replace ("# ([^]) (mms | http | https | ftp | telnet )(://)[.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) # Isu "," $1 $2 ", $ text );

You just need to change it?

$ Text = <TXT automatically adds links to the URLs in a text section, but some ubb code links cannot automatically add links. how can this problem be ruled out? Because ubb is automatically converted to a link. Like this: http://bbs.csdn.net/topics/new? Forum_id = PHPBase such as this: [ubb] http://bbs.csdn.net/topics/new? Forum_id = PHPBase [/ubb] TXT; echo preg_replace ("# ([^]) (mms | http | https | ftp | telnet )(://)[.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) # Isu "," $1 $2 ", $ text );


===
Thank you very much. I can use the one before you.
Return preg_replace ("# ([^ \]) (mms | http | https | ftp | telnet) (: //) [.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) (?> = \[)? # Isu "," $1 $2 ", $ str );

You can do that later. thank you ....

Another problem is how to deal with the = mark in front of it? The format is as follows:
[Url = http://bbs.csdn.net/topics/new? Forum_id = PHPBase]

Thanks. I changed it to this:
Echo preg_replace ("# ([^] | =]) (mms | http | https | ftp | telnet) (: //) [.: @/\ w \? \=\- \\\\_\#\;\% \,\! \ +] +) # Isu "," $1 $2 ", $ text );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.