Ask a Question related to PHP Development, Design and Development.
-
Krakatioison #1
Please help me with PREG_MATCH
Hi all,
I need a help to write a simple preg_match.
Imagine, I've got like 5kb of text where one part of the text always
starts with: [quote:129beec637]
and ends with: [/quote:129beec637]
Number after "[quote:" is always different and changing its length.
I need to parse this and display it using different color.
Just so, when I display the text, people could figure out where the
quotation starts and ends.
Could someone please help me with it?
Thanks a lot. Every help is very appreciated and helps me a lot.
Joe
Krakatioison Guest
-
trouble with preg_match()
Can anyone tell me why the following evaluates to false preg_match("/^.*X$/",$composited_rod_end_head_p) when ... -
preg_match
Hello, I would like to split a String containing ingredience with additional assigned footnotes... my problem I only get the first ingredience... -
preg_match allowing a-z AND å ä ö ü
I've been searching the net and Google news groups for a preg_match expression that will return true on strings containing (uppercase and... -
preg_match bug
Hey I wanted to see if anyone was getting the same problem. Using preg_match in the following pattern: "/<tr bgcolor="#FFFFFF">(.|\n)+?<\/tr>/" ... -
preg_match issue
I have a function that checks the syntax of a string using preg_match. This function is used in a loop and always hangs on the same string (7 out of... -
daniel #2
Re: Please help me with PREG_MATCH
A pattern like this would do the job:
'/\[quote:.*\](.*)\[\/quote:.*\]/'
preg_match('/\[quote:.*\](.*)\[\/quote:.*\]/', $string, $result);
$result[1...] will hold what is between the quote
But if I understand what you want to do, I would use preg_replace instead.
Something like that:
preg_replace('/\[quote:.*\](.*)\[\/quote:.*\]/', "<span
style=\"color:blue\">$1</span>", $string);
It also get rid of the [quote:...] and [/quote:...]
Dae
"Krakatioison" <com> a écrit dans le message de
news:417e3b2e$com...
daniel Guest
-
daniel #3
Re: Please help me with PREG_MATCH
A little correction:
The previous pattern would match [quote:...][/quote:..] that doesn't
match... it's not good
here is one that should fix that:
'/\[quote:(.*)\](.*)\[\/quote:.\\1]/'
preg_replace("/\[quote:(.*)\](.*)\[\/quote:\\1\]/", "<div
style=\"color:blue\">$2</div>", $a);
Dae
"daniel arsenault" <ca> a écrit dans le message
de news:iytfd.77183$videotron.net...
>
>[/ref]
daniel Guest
-
Oli #4
Re: Please help me with PREG_MATCH
"daniel arsenault" <ca> wrote:
Whilst this will work for some situations, it won't incorporate line-breaks
in the quote text, it is case-sensitive (i.e. you can't use [QUOTE:...]),
and doesn't check for invalid quotes (e.g. [quote:Z!"]).
It also doesn't match [quote] tags by number, and is greedy. For instance,
an input string of:
Some words [quote:1]HELLO[/quote:1] more words
[quote:2]GOODBYE[/quote:2] even more words
will only have one quote block converted, between [quote:1] and [/quote:2].
Oli.
Oli Guest
-
daniel #5
Re: Please help me with PREG_MATCH
> Whilst this will work for some situations, it won't incorporate
line-breaks
I totally forgot case and newlines, thanks.
For the check I don't really know what are valid characters so I'll assume
letters and digits:
Here would be the new pattern:
"/\[quote:([a-z0-9]*)\](.*)\[\/quote:\\1\]/is"
Possible use:
preg_replace("/\[quote:([a-z0-9]*)\](.*)\[\/quote:\\1\]/is", "<div
style=\"color:blue\">$2</div>", $a);
[/quote:2].
This one I fixed it by using backreference to make sure that opening and
closing [quote] match
Dae
daniel Guest



Reply With Quote

