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

Your name:

Reply:


Posted by greatprovider on 12/18/56 11:50

hah...that was the trick...thank you all...

one last question...now would anyone mind explaining me how "$1" works?

Rik wrote:
> 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

[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

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