Replace preg_replace. how to always [eat] a character before.-php Tutorial

Source: Internet
Author: User
Replace preg_replace. how can I always [eat] a character before... why should I use the following code to replace it. how can I always eat the previous character ...... the code is as follows... PHPcode $ newstextpreg_replace (. $ r [keyname]. u, & lt; ahref. $ r [keyurl]. t replace preg_replace. how can I always [eat] a character before...
Why should I use the following code to replace it? how can I always eat the previous character ......

The code is as follows...

PHP code
          $newstext = preg_replace('/'.$r[keyname].'/u',''.$r[keyname].'',$newstext,$public_r[repkeynum]);


PHP code
          $newstext = preg_replace('/[^=>]'.$r[keyname].'/u',''.$r[keyname].'',$newstext,$public_r[repkeynum]);


For example,... string = "my good day has started"
Key words: beauty

After the replacement, it became: My good day has started.

I am so depressed ....

------ Solution --------------------
No. What is your $ r [keyname?
------ Solution --------------------
Method 1 is correct
The second is what you said: [^ =>] will eat a character
------ Solution --------------------
Solution
------ Solution --------------------

$ Str = "My Wonderful Day has started ";
$ Newstext = preg_replace ('/beautiful/', 'Beautiful ', $ str );
Echo $ newstext;
?>

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.