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 );