In PHP, how to replace the label in a page with what the user wants to output

Source: Internet
Author: User

Introduction: Busan Line, exposing human nature,

————————————————————————————————————————————————————————————————————————————

Today, one of the simplest examples is how to read a label from another HTML page in PHP and show what the user wants to output.

First create a page named: test.html as shown:

<!doctype html>{$content}</body>

Requirement: Read {$content} and output what the user wants to output.

Next create another page, the mytest.php code is as follows:

<?PHP//assigns a value to a $content, and is the form of a string$content= ' I've been reading Lio Yimei's "Clumsy Life like Me";//reads all the contents of the Test.html file and returns it as a string$fileContent=file_get_contents(' test.html ');//Replace {$content} with $content content from the $filecontent string and return the string$str=Str_replace(' {$content} ',$content,$fileContent);//Final output ContentEcho $str;?>

Finally, through the page access, you can access the content, the results are as follows:

Summary: This is actually just a basic example of PHP, but also a thought, mainly for the smarty to do bedding. If something is wrong, please correct me, thank you!!

In PHP, how to replace the label in a page with what the user wants to output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.