Click to See Complete Forum and Search --> : preg_replace() Help


Joseph Witchard
08-23-2008, 02:29 PM
Is there a list of what all the different operators used in a preg_replace() function mean/do?

scragar
08-23-2008, 02:35 PM
http://php.net/manual/en/pcre.pattern.php

modifires go after the last /
the syntax notes are the ones inside the /s

Joseph Witchard
08-23-2008, 02:49 PM
modifires go after the last /
the syntax notes are the ones inside the /s

Can you explain that a bit more slowly? :o

scragar
08-23-2008, 02:59 PM
all the preg functions use the same syntax BTW:
preg_match("/Pattern Syntax/Pattern Modifiers", $something)
as per labels on the link I gave above. the modifiers cover the whole expression, so i makes the entire regExp incase sensitive etc.

click regExp details in the pattern syntax page for the complete list, be warned, it's long.

niczak
08-23-2008, 06:07 PM
Are you looking to match on a specific type of pattern (i.e. email, url, date, etc), if we knew that much we would be able to be a bit more helpful!

Joseph Witchard
09-01-2008, 07:27 PM
Well I'm going to be using it a lot for the script I'm writing. I'm trying to understand the theory, because I don't have a complete list of what I'm going to replace in my strings.

Kyleva2204
09-02-2008, 05:46 AM
If the search is a simple string, you can use str_replace() instead.

Joseph Witchard
09-02-2008, 04:05 PM
I tried that. For right now, I'm just trying to build an editor that replaces certain code in a string and turns it into a hyperlink, bold text, etc. So, it has to be done with preg_replace().

Kyleva2204
09-02-2008, 04:10 PM
Like such: PHP & BBCode (http://us.php.net/manual/en/intro.bbcode.php)?


Its not hard to install, if you know how to install PECL.. Which isn't TO hard.. Your webhost might already have it installed.. If your hosting your own site, you can try installing it yourself. See how to install on the link I provided.. I'm sure there is probably a BBCode class out there in the land of Google if you don't want to install anything on the server end.

Sure enough, a google search turned this up: Class that Parsed BBCodes for PHP (http://www.christian-seiler.de/projekte/php/bbcode/index_en.html)

Joseph Witchard
09-02-2008, 04:20 PM
While I still need to learn the logic of preg_replace(), that is going to help me a great deal. Thanks:D

Kyleva2204
09-02-2008, 04:41 PM
I found some good info at: http://evolt.org/node/22700/
I don't know if this says it, but I always used ( ) in my preg_replace search string for what I wanted replaced.

Also, some good info here: http://www.regular-expressions.info