0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

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)); 
} 
Community
  • 1
  • 1
TheGentleman
  • 2,324
  • 13
  • 17