Re: Help with preg_replace

From: Date: Thu, 08 Nov 2007 00:43:40 +0000
Subject: Re: Help with preg_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-264199@lists.php.net to get a copy of this message
Delimiters needed. Can use about anything not already in your pattern. "/" is very commonly used; but I like "#" or "%" generally; but, you can't use "%" because your pattern has it. $html = preg_replace("#%ResID#",$bookid,$html); Richard Luckhurst wrote:
Hi I am in the process of porting a Perl application to PHP and I have hit a snag with trying to substitute test within a file. I have looked at the PHP manual and believe I should be using preg_replace but I have tried the examples and am not getting the result I would expect. I would appreciate any help in getting this to work. In Perl I have the following $html = cat htmlfile; $html =~ s/%ResID/$bookid/g; which replaces each instance of %ResID with the contents of the variable $bookid In PHP I have tried $html = cat htmlfile; $html = preg_replace('%ResID',$bookid,$html); When I run this I find $html is empty rather than containing the file with the %ResID replaced with the contents of $bookid. I would appreciate any help with my understanding of preg_replace. Regards,
Richard Luckhurst                      Product Development
Exodus Systems - Sydney, Australia. rluckhurst@resmaster.com Tel: (+612) 4751-9633 Fax: (+612) 4751-9644 Web: www.resmaster.com ================================================= Exodus Systems - Smarter Systems, Better Business =================================================


« previous php.general (#264199) next »