About the preg_replace function, I want to use the preg_replace function to replace some characters in text with images. when I write this code, $ expression & nbsp; = "/@ /" can be executed normally /"; $ reexpression & nbsp; = ""; $ solve the preg_replace function
I want to use the preg_replace function to replace some characters in text with images.
When I write this code, it can be executed normally.
$ Expression = "/@ fangya /";
$ Reexpression = "fangya ";
$ Text = preg_replace ($ expression, '', $ text );
However, after I change it to an array, the image url becomes www.test.com/static/expression/array.gif.
$ Expression = array ("/@ fangya/", "/@ despise/", "/@ torture /");
$ Reexpression = array ("fangya", "despise", "torture ");
$ Text = preg_replace ($ expression, '', $ text );
I am new to php. I hope you can take a look.
------ Solution --------------------
The parameter value is calculated before the function is executed. So that is:
$ Replace = '';
$ Text = preg_replace ($ expression, $ replace, $ text );
// Because $ reexpression is a number Group, the combination of the number Group and reexpression will be array.gif.
Let's look at your requirements and write it again:
$ Text = 'Don't @ your teeth,-> @ despise <-';
$ Reexpression = array ("fangya", "despise", "torture ");
// Hope your program is better coded in UTF-8, u modifier is to avoid unexpected confusion in coding
$ Find = '# @ ('. join ('
------ Solution --------------------
', $ Reexpression).') # U ';
$ Replace = '';
$ Text = preg_replace ($ find, $ replace, $ text );
In addition, if your image is named in Chinese, you also need to pay attention to the encoding problems that may occur in IE, resulting in a 404 error in image loading.
Attached Manual: http://php.net/preg-replace