Re: Perl find and replace in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007. 03. 26, hétfő keltezéssel 21.17-kor rluckhurst@xxxxxxxxxxxxx ezt
írta:
> Hi All
> 
> I am porting some perl to PHP and have struck a small snag. The perl
> script has quite a few substitutions that take place so data can be fed
> into a html page.
> 
> The script uses the following perl syntax
> 
> $html = `cat search_results.html`;
> $html =~ s/%Accom/$accom/g;
> 
> As I understand perl that should cat the html file into a variable called
> $html. It should then perform a global substitution replacing %Accom with
> the contents of the variable $accom.
> 
> Is such a thing possible in PHP? If so how? I have been doing google
> searches for a while and can find no simple explanation of how to perform
> this in PHP. The nearest I can find is using a preg_replace but I am
> unsure if that will do what I need.
> 
> Does anyone know if this can be done?

$html = str_replace($search, $replace, file_get_contents($filename));

or you could use preg_replace if you want to search and replace based on
regular expressions
see:

http://hu2.php.net/manual/en/function.file-get-contents.php
http://hu2.php.net/manual/en/function.str-replace.php
http://hu2.php.net/manual/en/function.preg-replace.php

greets
Zoltán Németh

> 
> Regards
> 
> Richard Luckhurst
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux