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

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

WBOY
WBOYOriginal
2016-06-06 20:28:311069browse

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>

在我的网站中这段代码是报错的,我用的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>

在我的网站中这段代码是报错的,我用的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>

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

<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>
Statement:
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