dongyue5686 2012-09-03 17:36
浏览 33
已采纳

Str_replace什么都不做

I want to replace all £ to its HTML code £ => £ because it shows up as a ? in a diamond.

I am using the following code but it does nothing.

<?php
    include ("config.php");

    $get_id = mysql_real_escape_string($_GET['id']);
    $page_get = mysql_query("SELECT * FROM contents_page WHERE `id` = '$get_id'");
    while($page_row = mysql_fetch_assoc($page_get)) {
        $page_row["Page_Content"] = str_replace('£','&pound;',$page_row[Page_Content]);
        $smarty->assign('page_title',       $page_row['Page_Title']);
        $smarty->assign('page_content',     $page_row['Page_Content']);     
    }

    $smarty->display('page.tpl');
?>

I am using str_replace() but nothing happens its like it cannot see the £

  • 写回答

5条回答 默认 最新

  • dongqian1028 2012-09-03 18:08
    关注

    I had an encoding problem myself. Go to the database and see if the data is being garbled or not. if it is not, then set your connection attributes like this SET CHAR UTF8 before you connect to the database..

    $link1 = mysql_connect('localhost','user1','pass1',TRUE); 
    
    
    mysql_selectdb('db1',$link1); 
    
    mysql_set_charset('utf8',$link2);
    

    The other solution is to see to what the input was encoded before it went to the database, and then change the charset to that

    mysql_set_charset('latin1',$link2);

    for example.

    Any way, what I would do, I would still set my chars to utf-8 , output the results to the page.. see if the character is actually a pound sound, if it is a different symbol, I would put it in the string replace function instead of the pound symbol

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题