
例如:
<?php
session_start()
$_SESSION['age'] = 18
function initStr($str) {
$pattern = '/^(.*)\<\?php(.*)\?\>(.*)$/isU'
<a href="https://www.baidu.com/s?wd=preg_match&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLuj01PjN-nW6YuH0YP1uB0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtYPHf3PWfLnHmkn1nYnWndnWR" target="_blank" class="baidu-highlight">preg_match</a>($pattern, $str, $match)
ob_start()
echo $match[1]
eval($match[2])
echo $match[3]
$return = ob_get_contents()
ob_end_clean()
return $return
}
$ori_str = 'My age is <?php echo $_SESSION["age"]?>, how about you?'
$str = initStr($ori_str)
echo $str
?>
<?php$content="111\n222"
//先替换
$contents=str_replace("\n","<br/>",$content)
//再输出即可解决
echo $contents
?>
输出结果为:
111
222
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)