note 22531 deleted from function.preg-replace by dams

From: Date: Fri, 21 Jun 2002 02:00:27 +0000
Subject: note 22531 deleted from function.preg-replace by dams
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-32080@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> //

« previous php.notes (#32080) next »