You are here: Re: Trying to prevent duplicates in preg_replace Regex « PHP Programming Language « IT news, forums, messages
Re: Trying to prevent duplicates in preg_replace Regex

Posted by erikcw on 02/24/07 18:05

On Feb 24, 9:45 am, "Janwillem Borleffs" <j...@jwscripts.com> wrote:
> erikcw wrote:
> > Here is what I have so far - it is close, but I keep ending up with
> > duplicate brackets.
>
> [...]
>
> Often, simplicity = bless:
>
> $PATTERNS = array('/(\[|\])/', '/([^\r\n]+)/');
> $REPLACEMENTS = array('', '[$1]');
>
> JW

Thank you for your reply.

Your selution is simple and elegant. Unfortunatly, it puts brackets
around every line. I need it to ignore lines with "" around them, as
well as line that start with a '-' and lines that end in a ** 0.00
need the ending bracket before the **.

So, the output should look like this:
$input = 'this
is
a
test
"this"
"is"
"a"
[this]
[is]
[a]
test ** 93.23
test 2 ** 10.05
-this
-is
-a
another good test
';

$OUTPUT = '[this]
[is]
[a]
[test]
"this"
"is"
"a"
[this]
[is]
[a]
[test] ** 93.23
[test 2] ** 10.05
-this
-is
-a
[another good test]
';

What needs to be changed in your pattern to do this?

Thanks so much!
Erik

 

Navigation:

[Reply to this 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

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