Reply to Re: can't find the right PCRE pattern for a preg_match_all

Your name:

Reply:


Posted by Chung Leong on 12/18/06 11:50

greatprovider wrote:
> the formulas are inputted into a database in the format:
> "Na**3C**6H**5O**7*2H**20"
> i query the database and pass the list of unformated formulas through
> this function in a loop.
>
> function format_replace($formula) {
> $search = "/(\*{2}[\d]+)/";
> $replace = "<sub>\l</sub>";
> $formatted = preg_replace( $search, $replace, $formula);
> return $formatted;
> }
> the result i get for this is: Na\lC\lH\lO\l*2H\l (where "\l" is
> subscripted).

You mistyped the code I provided in a couple places. There is no need
for brackets around \d as it's already a class. You want the
parentheses around \d+, not the whole expression, since you only want
the number (and not the two asterisk). And the replacement is \1 not
\l--meaning what's inside the first pair of parentheses.

Just copy-and-paste.

[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

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