Read the file and replace it with regular expression? ? _PHP Tutorial

WBOY
Release: 2016-07-13 10:51:36
Original
871 people have browsed it




Read the file and replace it with regular expression? ?



I want to replace 2.xml in the attachment with regular expressions so that it becomes as follows: (Actually, it means changing the tag)
That is, let


programming

Rasmus Lerdorf
Kevin Tatroe

1-56592-610-2
A great book!


Dress up as


programming

Rasmus Lerdorf
Kevin Tatroe

1-56692-610-2


In fact, the label is replaced and the value remains unchanged.
How to write this program? First, we need to read the file, and then how to perform regular replacement? In addition, how to write xml tags as regular expressions? Thank you

Let me answer

Attachment: Your user group cannot download or view attachments


D8888D reply content------------------------------------------------- ----------
$ftext = file_get_contents($filename);
preg_replace('String regular expression to be replaced', 'Replacement content',$ftext);

D8888D reply content------------------------------------------------- ----------
How about writing a few more str_replaces..

D8888D reply content------------------------------------------------- ----------
Is it correct for me to write this:

$xml = "books.xml";
$f = fopen( 'books.xml', 'r' );
while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );

$xmla=preg_replace( '/', 'lee', $xml );

$xmla=preg_replace( '
', '/lee', $xmla );



echo "$xmla";

?>

D8888D reply content------------------------------------------------- ----------
Is it correct for me to write this:

lxcupid published on 2009-6-15 13:04 [url=http://bbs.111cn.cn/redirect.php?goto=findpost&pid=1068481&ptid=128175]Link tag[img]http://bbs.111cn.cn /images/common/back.gif[/img][/url]




$xml = implode("",file('books.xml'));



$xmla=preg_replace( '/', 'lee', $xml );



$xmla=preg_replace( '
', '/lee', $xmla );







echo "$xmla";



?>


Copy code

D8888D reply content------------------------------------------------- ----------
$xml = implode("",file('books.xml'));

$xml=str_replace( array('',''), array('',''), $xml ); // Replace with , replace with


Copy code

D8888D reply content------------------------------------------------- ----------
Thank you, but it seems that part of the sticker is missing, haha. But the result is not a new xml format.

D8888D reply content------------------------------------------------- ----------


The following is the code according to the code above:
$xml = implode("",file('books.xml'));
$data=str_replace( array('',''), array('',''), $xml );
// Replace with and with
echo $data;
?>
But the running result is:
Rasmus Lerdorf Kevin Tatroe 1-56592-610-2

Why can't I display the new xml file I want? ?
Attachment: Your user group cannot download or view attachments
D8888D reply content------------------------------------------------- ----------
htmlentities() output plus this function

D8888D reply content------------------------------------------------- ----------
Please be more specific upstairs, thank you


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632562.htmlTechArticleRead the file and replace it with regular expression? ? I want to replace 2.xml in the attachment with regular expressions so that it becomes as follows: (Actually, it means changing the tags) That is, programming Rasmus Lerdorf Kevin Tatroe 1-5...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template