regular expression : {link}

This is a discussion on regular expression : {link} within the PHP Language forums, part of the PHP Programming Forums category; Can someone help me to make a regular expression for this sort of replacement : text with {link:pagehref}a link{/...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2006
gehegeradeaus@gmail.com
 
Posts: n/a
Default regular expression : {link}

Can someone help me to make a regular expression for this sort of
replacement :

text with {link:pagehref}a link{/link}.

replace to ->

text with <a href="pagehref">a link</a>

I tried several things but nothing seems to work... e.g.

$value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
target=\"_blank\">$2</a>",$value);

Thanks in advance!

Reply With Quote
  #2 (permalink)  
Old 09-12-2006
mutale82@gmail.com
 
Posts: n/a
Default Re: regular expression : {link}


gehegeradeaus@gmail.com wrote:
> Can someone help me to make a regular expression for this sort of
> replacement :
>
> text with {link:pagehref}a link{/link}.
>
> replace to ->
>
> text with <a href="pagehref">a link</a>
>
> I tried several things but nothing seems to work... e.g.
>
> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
> target=\"_blank\">$2</a>",$value);
>
> Thanks in advance!


try to use str_replace() instead...
see it here: http://de.php.net/str_replace

Reply With Quote
  #3 (permalink)  
Old 09-12-2006
Ac1d^
 
Posts: n/a
Default Re: regular expression : {link}

gehegeradeaus@gmail.com napisal(a):
> Can someone help me to make a regular expression for this sort of
> replacement :
>
> text with {link:pagehref}a link{/link}.
>
> replace to ->
>
> text with <a href="pagehref">a link</a>
>
> I tried several things but nothing seems to work... e.g.
>
> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
> target=\"_blank\">$2</a>",$value);
>
> Thanks in advance!


Try this pattern.
"/\{link\:(.*)\}(.*)\{\/link\}\s/"
rest of the code looks fine.

You can also have a look at the comments below preg-replace Description
at www.php.net. There is a lot of usefull informations how to use it,

http://uk2.php.net/manual/en/function.preg-replace.php

Reply With Quote
  #4 (permalink)  
Old 09-12-2006
Kimmo Laine
 
Posts: n/a
Default Re: regular expression : {link}

"Ac1d^" <adam82s@gmail.com> wrote in message
news:1158054059.855759.172420@i42g2000cwa.googlegr oups.com...
> gehegeradeaus@gmail.com napisal(a):
>> Can someone help me to make a regular expression for this sort of
>> replacement :
>>
>> text with {link:pagehref}a link{/link}.
>>
>> replace to ->
>>
>> text with <a href="pagehref">a link</a>
>>
>> I tried several things but nothing seems to work... e.g.
>>
>> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
>> target=\"_blank\">$2</a>",$value);
>>
>> Thanks in advance!

>
> Try this pattern.
> "/\{link\:(.*)\}(.*)\{\/link\}\s/"
> rest of the code looks fine.



The problem is that {link:(.*)} matches to the entire "{link:pagehref}a
link{/link}", it reaches the last occurance of } untill stops. Instead of .*
the pattern should be (^})* ie. match anything but }, then it should stop at
the first } which closes the {link} pseudotag.
something like:

"/\{link\:((^})*)\}(^{*)\{\/link\}\s/"


--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #5 (permalink)  
Old 09-12-2006
gehegeradeaus@gmail.com
 
Posts: n/a
Default Re: regular expression : {link}


Kimmo Laine schreef:

> "Ac1d^" <adam82s@gmail.com> wrote in message
> news:1158054059.855759.172420@i42g2000cwa.googlegr oups.com...
> > gehegeradeaus@gmail.com napisal(a):
> >> Can someone help me to make a regular expression for this sort of
> >> replacement :
> >>
> >> text with {link:pagehref}a link{/link}.
> >>
> >> replace to ->
> >>
> >> text with <a href="pagehref">a link</a>
> >>
> >> I tried several things but nothing seems to work... e.g.
> >>
> >> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
> >> target=\"_blank\">$2</a>",$value);
> >>
> >> Thanks in advance!

> >
> > Try this pattern.
> > "/\{link\:(.*)\}(.*)\{\/link\}\s/"
> > rest of the code looks fine.

>
>
> The problem is that {link:(.*)} matches to the entire "{link:pagehref}a
> link{/link}", it reaches the last occurance of } untill stops. Instead of .*
> the pattern should be (^})* ie. match anything but }, then it should stop at
> the first } which closes the {link} pseudotag.
> something like:
>
> "/\{link\:((^})*)\}(^{*)\{\/link\}\s/"
>
>
> --


Unfortunately still nothing, I tried both of the solutions above... but
the replacement doesn't work :

http://cmdstud.khlim.be/~bbrughmans/tmp.phps and
http://cmdstud.khlim.be/~bbrughmans/tmp.php

Reply With Quote
  #6 (permalink)  
Old 09-12-2006
gehegeradeaus@gmail.com
 
Posts: n/a
Default Re: regular expression : {link}


mutale82@gmail.com schreef:

> gehegeradeaus@gmail.com wrote:
> > Can someone help me to make a regular expression for this sort of
> > replacement :
> >
> > text with {link:pagehref}a link{/link}.
> >
> > replace to ->
> >
> > text with <a href="pagehref">a link</a>
> >
> > I tried several things but nothing seems to work... e.g.
> >
> > $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a href=\"$1\"
> > target=\"_blank\">$2</a>",$value);
> >
> > Thanks in advance!

>
> try to use str_replace() instead...
> see it here: http://de.php.net/str_replace


I don't think I can use str_replace in this case, because it is a
dynamic tag.

Reply With Quote
  #7 (permalink)  
Old 09-12-2006
Kimmo Laine
 
Posts: n/a
Default Re: regular expression : {link}

<gehegeradeaus@gmail.com> wrote in message
news:1158060714.858365.181920@i3g2000cwc.googlegro ups.com...
>
> Kimmo Laine schreef:
>
>> "Ac1d^" <adam82s@gmail.com> wrote in message
>> news:1158054059.855759.172420@i42g2000cwa.googlegr oups.com...
>> > gehegeradeaus@gmail.com napisal(a):
>> >> Can someone help me to make a regular expression for this sort of
>> >> replacement :
>> >>
>> >> text with {link:pagehref}a link{/link}.
>> >>
>> >> replace to ->
>> >>
>> >> text with <a href="pagehref">a link</a>
>> >>
>> >> I tried several things but nothing seems to work... e.g.
>> >>
>> >> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a
>> >> href=\"$1\"
>> >> target=\"_blank\">$2</a>",$value);
>> >>
>> >> Thanks in advance!
>> >
>> > Try this pattern.
>> > "/\{link\:(.*)\}(.*)\{\/link\}\s/"
>> > rest of the code looks fine.

>>
>>
>> The problem is that {link:(.*)} matches to the entire "{link:pagehref}a
>> link{/link}", it reaches the last occurance of } untill stops. Instead of
>> .*
>> the pattern should be (^})* ie. match anything but }, then it should stop
>> at
>> the first } which closes the {link} pseudotag.
>> something like:
>>
>> "/\{link\:((^})*)\}(^{*)\{\/link\}\s/"
>>
>>
>> --

>
> Unfortunately still nothing, I tried both of the solutions above... but
> the replacement doesn't work


I tried this with preg_match:

/{link:([^}]*)}([^{]*){\/link}/

result:
Array (
[0] => {link:pagehref}a link{/link}
[1] => pagehref
[2] => a link
)

That should do it... modify it to suit your needs

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #8 (permalink)  
Old 09-12-2006
gehegeradeaus@gmail.com
 
Posts: n/a
Default Re: regular expression : {link}


Kimmo Laine schreef:

> <gehegeradeaus@gmail.com> wrote in message
> news:1158060714.858365.181920@i3g2000cwc.googlegro ups.com...
> >
> > Kimmo Laine schreef:
> >
> >> "Ac1d^" <adam82s@gmail.com> wrote in message
> >> news:1158054059.855759.172420@i42g2000cwa.googlegr oups.com...
> >> > gehegeradeaus@gmail.com napisal(a):
> >> >> Can someone help me to make a regular expression for this sort of
> >> >> replacement :
> >> >>
> >> >> text with {link:pagehref}a link{/link}.
> >> >>
> >> >> replace to ->
> >> >>
> >> >> text with <a href="pagehref">a link</a>
> >> >>
> >> >> I tried several things but nothing seems to work... e.g.
> >> >>
> >> >> $value=preg_replace("/\{link\:(.+?)\}(.+?)\{\/link\}/s","<a
> >> >> href=\"$1\"
> >> >> target=\"_blank\">$2</a>",$value);
> >> >>
> >> >> Thanks in advance!
> >> >
> >> > Try this pattern.
> >> > "/\{link\:(.*)\}(.*)\{\/link\}\s/"
> >> > rest of the code looks fine.
> >>
> >>
> >> The problem is that {link:(.*)} matches to the entire "{link:pagehref}a
> >> link{/link}", it reaches the last occurance of } untill stops. Instead of
> >> .*
> >> the pattern should be (^})* ie. match anything but }, then it should stop
> >> at
> >> the first } which closes the {link} pseudotag.
> >> something like:
> >>
> >> "/\{link\:((^})*)\}(^{*)\{\/link\}\s/"
> >>
> >>
> >> --

> >
> > Unfortunately still nothing, I tried both of the solutions above... but
> > the replacement doesn't work

>
> I tried this with preg_match:
>
> /{link:([^}]*)}([^{]*){\/link}/
>
> result:
> Array (
> [0] => {link:pagehref}a link{/link}
> [1] => pagehref
> [2] => a link
> )
>
> That should do it... modify it to suit your needs
>
> --



thanks, it does work now :)

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0