Reply to Trying to prevent duplicates in preg_replace Regex

Your name:

Reply:


Posted by erikcw on 02/23/07 20:32

Hi all,

I'm trying to write a regex pattern to use in preg_replace. Basically
I want to put [brackets] around every line (\n) in this variable.
However, I need to exclude lines that already have brackets or
quotation marks around them as well as lines that start with a
hyphen. Lastly the lines with ** need the brackets before the **,
instead of at the end of the line.

Here is what I have so far - it is close, but I keep ending up with
duplicate brackets.

$temp = 'this
is
a
test
"this"
"is"
"a"
[this]
[is]
[a]
test ** 93.23
test 2 ** 10.05
-this
-is
-a
another good test
';
$PATTERNS = array("/^[^\"\[]/m", "/[^\"\]]$/m", "/[\r\n]+/", "/ \*\*
(.*)]/");
$REPLACEMENTS = array("[", "]", "]\n[", "] \*\* $1");
$output1 = trim(preg_replace($PATTERNS, $REPLACEMENTS, trim($temp)));
print_r($output1);

Thanks for your help!
Erik

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация