佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1065|回复: 5

要如何将代码在PHP显示。。。。

[复制链接]
发表于 5-8-2009 07:34 AM | 显示全部楼层 |阅读模式
数据库原来的代码:<font color=red>TEST</font>
有什么方法让代码用PHP显示时,只是显示TEST而已。而不会显示红色的TEST。
回复

使用道具 举报


ADVERTISEMENT

发表于 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来处理。
  1. $string = '<font color=red>TEST</font>';
  2. $pattern = '/([<|<\/].*?>(.*?)/';
  3. $replace = '\2';
  4. echo preg_replace($pattern, $replace, $string);
复制代码
如果只是抽取font tag的话可以这样写
  1. $string = '<font color=red>TEST</font>';
  2. $pattern = '/(<font.*?>)(.*?)(<\/font>)/is';
  3. $replace = '\2';
复制代码

[ 本帖最后由 jinn 于 6-8-2009 01:46 AM 编辑 ]
回复

使用道具 举报

发表于 6-8-2009 02:35 PM | 显示全部楼层
我才發現這個函數,直接去除html,php tag  

strip_tags($font);
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 5-12-2025 11:40 PM , Processed in 0.152748 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表