473,508 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
3 2065
Krakatioison wrote:
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


Do you want to echo the literal text: [quote etc] or what's between the
quote tags ?
Jul 17 '05 #2
Hi Pjotr,
I need to echo only the original text between "quote:"
Thanks for trying to help me.
Joe


"Pjotr Wedersteers" <pj***@wedersteers.com> wrote in message
news:41***********************@news.xs4all.nl...
Krakatioison wrote:
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


Do you want to echo the literal text: [quote etc] or what's between the
quote tags ?

Jul 17 '05 #3
Krakatioison wrote:
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]
I assumed the number is a hexadecimal number.
Number after "[quote:" is always different and changing its length.
<?php
$text = 'before [quote:1abc08f] middle [/quote:1abc08f] after';

$rx = '/\[quote:([0-9a-fA-f]+)\](.*)\[\/quote:\1\]/';
$text2 = preg_replace($rx, '***\2***', $text);

echo $text, "\n";
echo $text2, "\n";
?>
I need to parse this and display it using different color.
Replace the "***" with whatever you prefer.
Just so, when I display the text, people could figure out where the
quotation starts and ends.


Happy Coding :-)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #4

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

Similar topics

2
4233
by: fartsniff | last post by:
hello all, here is a preg_match routine that i am using. basically, $image is set in some code above, and it can be either st-1.gif or sb-1.gif (actually it randomly picks them from about 100...
2
4679
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
22
2740
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
0
1324
by: awebguynow | last post by:
I ran across this code, and it kind of made me nervous: (as an email validator) if ( !preg_match("/.*\@.*\..*/", $_POST) | preg_match("/(\)/", $_POST) ) 1) from bitwise experience with "C",...
4
14817
by: squash | last post by:
I have a string equal to 'www/' that I want to use in a preg_match. Php keeps giving me the warning: Warning: preg_match(): Unknown modifier '/' How can I escape the string so the / in www/ is...
5
7407
by: Mark Woodward | last post by:
Hi all, I'm trying to validate text in a HTML input field. How do I *allow* a single quote? // catch any nasty characters (eg !@#$%^&*()/\) $match = '/^+$/'; $valid_srch = preg_match($match,...
6
10218
by: mantrid | last post by:
Hello Found this piece of code using preg_match to check file types during upload of files. $allowed_file_types = "(jpg|jpeg|gif|bmp|png)"; preg_match("/\." . $allowed_file_types . "$/i",...
9
1993
by: Synapse Syndrome | last post by:
Hi I've been given what I am told is a PHP script to be used on my server. I do not know any PHP. I am trying to use a feature of a program called ArchiCAD. This feauture allows CAD drawing...
2
4238
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
8
3978
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
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
7498
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...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.