Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex for hyperlink

Status
Not open for further replies.

miguelisboa

Technical User
Apr 29, 2006
13
PT
i got the following from a book:
its a regex that works IF the word(s) dont have any special chars, like:
página, or
maçã
here it is:

$texto = ereg_replace('\[L]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[EL]','<a class="texto" href="\\1">\\1</a>', $texto);
$texto = ereg_replace('\[L=([-_./a-zA-Z0-9!&%#?+,\'=:~]+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,\'"=:;~]+)\[EL]',
'<a class="texto" href="\\1">\\2</a>', $texto);

see this example:
visit this [L=[URL unfurl="true"]http://www.tek-tips.com[/URL]] página[EL]
what is missing there ?
note: it works if i use "pagina" instead of "página"
Thanks in advance
 
It looks like the problem is in that your character class:

[-_./a-zA-Z0-9!&%#?+,\'=:~]

a-z and A-Z don't cover the extended characters such as á

using \w in your character class should match these as well:

[-_./\w0-9!&%#?+,\'=:~]
 
thanks, MrPlough69 for your answer
i tested your sugestion but it doesnt work
in meanwhile i was told i had to have multibyte support:

and the regex shoud be as this:
$texto = mb_ereg_replace('\[L=([-_./a-zA-Z0-9!&%#?+,\'=:~]+)] *(\w+)\[EL]',
'<a class="texto" href="\\1">\\2</a>', $texto);

i did install mbstring extension and all this works; the only problem i've o far is that it does not support two or more words, like:

visit this [L=[URL unfurl="true"]http://www.tek-tips.com[/URL]] good página[EL]
anyway thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top