note 9160 added to str_replace

From: Date: Thu, 19 Oct 2000 12:14:02 +0000
Subject: note 9160 added to str_replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-6699@lists.php.net to get a copy of this message
I used str_replace to make a php script that translates an HTML page into its PHP equivalent (the PHP code will so generate the original HTML page) : fputs($php_file,"<?");fputs($php_file,"\n"); while(!feof($html_file)) { $line = fgets($html_file,4096); $l = strlen($line); if(($line!="")&&($l>2)) {//removing chr(10) and chr(13) : $line = substr($line,0,strlen($line)-2); //Replacing the '"' of the HTML by '\"' in PHP code: $line2 = str_replace ("\"", "\\\"", "$line"); //Note : '\n' in JavaScript code should also be replaced // by '\\n' - to be done ... //Adding 'print("...");' : $newLine = "print(\""."$line2"."\\n\");"; fputs($php_file,$newLine); fputs($php_file,"\n"); } } fputs($php_file,"?>");fputs($php_file,"\n"); http://www.php.net/manual/function.str-replace.php

« previous php.notes (#6699) next »