473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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!

Sep 12 '06 #1
7 1943

ge***********@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

Sep 12 '06 #2
ge***********@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

Sep 12 '06 #3
"Ac1d^" <ad*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
ge***********@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
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Sep 12 '06 #4

Kimmo Laine schreef:
"Ac1d^" <ad*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
ge***********@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

Sep 12 '06 #5

mu******@gmail.com schreef:
ge***********@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.

Sep 12 '06 #6
<ge***********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
Kimmo Laine schreef:
>"Ac1d^" <ad*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
ge***********@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
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Sep 12 '06 #7

Kimmo Laine schreef:
<ge***********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...

Kimmo Laine schreef:
"Ac1d^" <ad*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
ge***********@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 :)

Sep 12 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: radawson218 | last post by:
Hi, I'm a complete newbie when using regular expressions, so forgive me if my delimma sounds stupid. I have an ASP.NET app that utilizes url rewriting. It's a simple bookstore that allows...
2
by: Mike Andrews | last post by:
Guys, I've got a regular expression that will just not work. I can't get it work properly and I would like to see if someone out there can tell me if I'm doing this wrong, or if there is a...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
3
by: Lisa Bogart | last post by:
I am trying to take a string and parse it out into multiple strings based on a pattern but am stuck and am hoping someone can give me a clue. My pattern looks like so: sMatch =...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
4
by: rufus | last post by:
I need to parse some HTML and add links to some keywords (up to 1000) defined in a DB table. What I need to do is search for these keywords and if they are not already a link, and they are not...
1
by: coder57 | last post by:
Basically I have a local html file, called file1.html it has a series of links (with a particular domain name) in addition to the html code, I am trying to follow each of these links (based on the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.