Solving about preg_replace functions

Source: Internet
Author: User
I want to use the Preg_replace function to replace some characters in text with images.
When I write like this, I can do it normally.
$expression = "/@ bared teeth"; $reexpression = "bared teeth"; $text =preg_replace ($expression, ", $text);

But when I changed to the group after the replacement of the image URL has become www.test.com/static/expression/Array.gif.
$expression =array ("/@", "/@ despise/", "/@ Torture/"), $reexpression =array ("Bared teeth", "contempt", "torment"), $text =preg_replace ($expression, ", $text);

I just contacted PHP, I hope you can help to see


Reply to discussion (solution)

The value of the parameter is computed before the function is executed. So it is:
$replace = ";
$text = Preg_replace ($expression, $replace, $text);
Since $reexpression are arrays, the array and string are connected to Array.gif

Look at your needs and re-write:

$text = ' Don't->@, despise <-'; $reexpression =array ("Bared teeth", "despise", "torment");//Hope your program is best coded with UTF-8, the U modifier is to avoid accidental confusion in coding $find = ' #@ ('. Join (' | ', $reexpression). ') #u '; $replace = '; $text = Preg_replace ($find, $replace, $text);

In addition, your image in Chinese name, but also need to pay attention to the possible code generated under IE, resulting in a picture loading 404 error

Attached manual: Http://php.net/preg-replace

The value of the parameter is computed before the function is executed. So it is:
$replace = ";
$text = Preg_replace ($expression, $replace, $text);
Since $reexpression are arrays, so ...
Thank you so much, I'm finally ready.

  • Related Article

    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.