Home > Backend Development > PHP Tutorial > php的正则闭包500错误!快来看看啊!!

php的正则闭包500错误!快来看看啊!!

WBOY
Release: 2016-06-06 20:28:31
Original
1093 people have browsed it

PHP求助!

<code>function str_emoji($str){
  function empic($h){
    $p=dechex(str_replace(array('',';'),'',$h));
    return '<img src="'.%24_POST%5B'face'%5D.%24p.'.png" alt="'.$h.'" class="smiley">';
  };
  $str=preg_replace('#(\&\#[0-9]{6}\;)#ie','empic("\\1")',$str);
  return $str;
};
$com_print=str_emoji('aaa🐛🐍bbb');</code>
Copy after login
Copy after login

在我的网站中这段代码是报错的,我用的PHP版本是5.3.28
我在SAE中测试是没有问题的,版本是5.3 http://parktest.sinaapp.com/

回复内容:

PHP求助!

<code>function str_emoji($str){
  function empic($h){
    $p=dechex(str_replace(array('',';'),'',$h));
    return '<img src="'.%24_POST%5B'face'%5D.%24p.'.png" alt="'.$h.'" class="smiley">';
  };
  $str=preg_replace('#(\&\#[0-9]{6}\;)#ie','empic("\\1")',$str);
  return $str;
};
$com_print=str_emoji('aaa🐛🐍bbb');</code>
Copy after login
Copy after login

在我的网站中这段代码是报错的,我用的PHP版本是5.3.28
我在SAE中测试是没有问题的,版本是5.3 http://parktest.sinaapp.com/

是不是死循环了????

<code class="php">function str_emoji($str,$cdn){
  function empic($h){
    $p=dechex(str_replace(array('',';'),'',$h));
    return '<img src="'.%24cdn.%24p.'.png" alt="'.$h.'" class="smiley">';
  };
  $str=preg_replace('#(\&\#[0-9]{6}\;)#ie','empic("\\1")',$str);
  return $str;
};

$com_print=str_emoji('aaa🐛🐍bbb',$_POST['face']);</code>
Copy after login

好吧,最后还是要我自己来写答案。

<code>function pic_emoji($str,$cdn){
  return preg_replace_callback(
    '/\&\#[0-9]{6}\;/',
    function ($m) use ($cdn){
      $p=dechex(str_replace(array('',';'),'',$m[0]));
      return '<img src="'.%24cdn.%24p.'.png" alt="'.$m[0].'" class="smiley">';
    },
    $str
  );
};</code>
Copy after login
Related labels:
php
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