Reply to Re: regular expression : {link}

Your name:

Reply:


Posted by Kimmo Laine on 09/12/06 12:07

<gehegeradeaus@gmail.com> wrote in message
news:1158060714.858365.181920@i3g2000cwc.googlegroups.com...
>
> Kimmo Laine schreef:
>
>> "Ac1d^" <adam82s@gmail.com> wrote in message
>> news:1158054059.855759.172420@i42g2000cwa.googlegroups.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)

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация