note 22531 added to function.preg-replace
| From: | dburbol@php.net | Date: | Fri, 21 Jun 2002 01:53:18 +0000 |
| Subject: | note 22531 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32069@lists.php.net to get a copy of this message | ||
wahoo! I figured it out! I just hadn't gotten to the page on Greedy vs. Non-Greedy searches.
Let me answer my own question for everyone's benifit...
//this is what I found works
// Bold, Italics, Underlined replacing...
$beitrag = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>",
$beitrag);
$beitrag = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>",
$beitrag);
$beitrag = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>",
$beitrag);
//
// now what the does that mean?
// # # <--- everything in between those is a "pattern"
// '\[' and '\]' denote the literal characters [ and ]
// ( ) <--- everything in between those is a substring that is access later with "\\1"
// . <--- says "any character"
// *? <--- says "I want 0 or more __blank__ but I'm NOT greedy, I want the shortest
string possible as a result"
// s <--- since it's AFTER the pattern markers, it says "make our . operator match
ANY character INCLUDING newline, aka '\n' "
// i <--- since it's AFTER the pattern markers, it says "we are NOT case
sensitive"
// \\1 <--- as mentioned, is basically like a variable that holds the string that was inside our
"(" and ")"
//
// so the "bold" replace says this:
// find "[b]" or "[B]", then go as FEW characters as posible until you reach a
[/b] or a [/B],
// then replace it with "<b>" then all the characters we passed over, and then
</b>
//
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+22531
http://master.php.net/manage/user-notes.php?action=delete+22531
http://master.php.net/manage/user-notes.php?action=reject+22531