douzi115522 2016-04-02 14:53
浏览 87

关于sql和str_replace函数

First of all, thanks to everyone for helping me, and please apologize my English, I'm trying to do the best :)

This is what I wanna do:

I have a table in MySQL database, named acciones, I want to every "action" registered in that table make a replace in the text printed on screen:

<?php
    include('../procesos/abre_conexion.php'); 
    $query99 = "SELECT * from acciones";     
    // This line make the query 
    $result99 = mysql_query($query99);  
    $registro99 = mysql_fetch_array($result99)   
?> 
<?php 
    // create the function 
    function howls($valor) { 
        // set the variable // saving as array // possible texts 
        $variables = array('$registro99[original]',); 
        // $imagenes, tambien contendra un array 
        // with the replace text 
        $sus = array('$registro99[reemplazo]',); 
        // making the replace 
        return (str_replace($variables, $sus, $valor)); 
    } 
    // starting function 
    ob_start("howls"); 
?> 
#SalirA beber Cerveza Montoro en barrio santo con Andreita. 
<?php 
    // ending function 
    ob_end_flush(); 
?>
<? include('../procesos/cierra_conexion.php'); ?>

But it don't works, any suggestion?

  • 写回答

1条回答 默认 最新

  • duanqian9593 2016-04-02 15:19
    关注

    Firstly, you should NOT be using the mysql_* functions. They are deprecated and completely removed from PHP7.

    As to what is happening with your code. You shouldn't single quote the $registro variables. If you do need them quoted for some reason, you need to double-quote them.

    function howls($valor) { 
        // set the variable // saving as array // possible texts 
        $variables = array("{$registro99[original]}",); 
        // $imagenes, tambien contendra un array 
        // with the replace text 
        $sus = array("{$registro99[reemplazo]}",); 
        // making the replace 
        return (str_replace($variables, $sus, $valor)); 
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line