You are here: Re: regexps: dollar sign, lookaheads/behinds and speedquestions « PHP Programming Language « IT news, forums, messages
Re: regexps: dollar sign, lookaheads/behinds and speedquestions

Posted by Toby A Inkster on 02/25/07 23:04

Yorian wrote:

> However this didn't work, even if I try to just replace the dollar
> sign (by a b) it doesn't work properly:
>
> preg_replace("/\$/", "b", $string);

You need to either use single-quote marks, or double-escape it.

"/\\\$/"
'/\$/'

This is because the dollar sign has two special meanings in this case.
Dollar signs in double-quotes are used by PHP for interpolation, so need
escaping. Dollar signs in PCREs are used to mark the end of a string, so
need escaping. Hence the double-escape. (i.e. three slashes!)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

 

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

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