You are here: Re: can't find the right PCRE pattern for a preg_match_all « PHP Programming Language « IT news, forums, messages
Re: can't find the right PCRE pattern for a preg_match_all

Posted by Rik on 10/15/51 11:49

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).

Euhm, I think i found the problem after numerous, all working, examples:

Use the NUMBER 1, it's hard in certain fonts to see the difference, but you
write 'l', not'1'.....


$search = '/\*{2}([\d]+)/';
$replace = '<sub>$1</sub>';

Using $N instead of \N is preferred.
Single quotes so PHP won't try to match a '$' to an existing variable.

Grtz,
--
Rik Wasmus

 

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

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