|
查看: 1065|回复: 5
|
要如何将代码在PHP显示。。。。
[复制链接]
|
|
|
数据库原来的代码:<font color=red>TEST</font>
有什么方法让代码用PHP显示时,只是显示TEST而已。而不会显示红色的TEST。 |
|
|
|
|
|
|
|
|
|
|
发表于 5-8-2009 07:36 AM
|
显示全部楼层
|
echo "<font color='red'>TEST</font>" |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-8-2009 06:56 PM
|
显示全部楼层
|
我要的是显示TEST而已。而不会显示红色的TEST |
|
|
|
|
|
|
|
|
|
|
发表于 5-8-2009 08:37 PM
|
显示全部楼层
如果red是固定的话
$font='<font color=red>TEST</font>';
$result=str_replace (' color=red','',$font);
//$result=<font>TEST</font>
不固定的话
$result=str_replace ('color=','',$font);//不懂会不会违反w3c标准
//$result=<font red>TEST</font>
最好的方法是用16进位3位数来表示颜色
$font='<font color=#000>TEST</font>';
$color=' color='.substr($font, 12, 4);// color=#000
$result=str_replace ($color,'',$font);
//$result=<font>TEST</font>
[ 本帖最后由 y小叶y 于 5-8-2009 08:39 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 6-8-2009 01:17 AM
|
显示全部楼层
试试看这个,但会有些问题,比如:<tm>kdfjdkfjkdfjd jfkdjff 里的<tm>将会被当成html tag来处理。- $string = '<font color=red>TEST</font>';
- $pattern = '/([<|<\/].*?>(.*?)/';
- $replace = '\2';
- echo preg_replace($pattern, $replace, $string);
复制代码 如果只是抽取font tag的话可以这样写- $string = '<font color=red>TEST</font>';
- $pattern = '/(<font.*?>)(.*?)(<\/font>)/is';
- $replace = '\2';
复制代码
[ 本帖最后由 jinn 于 6-8-2009 01:46 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 6-8-2009 02:35 PM
|
显示全部楼层
我才發現這個函數,直接去除html,php tag
strip_tags($font); |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|