str_replace as default for every record?

Discussion in 'PHP' started by jmansa, Oct 19, 2008.

  1. #1
    Is it possible to make an str_replace default on every record?

    As it is now I have to make the code below everytime I get something from my db:
    $sql = $db->sql_query("SELECT * FROM ".$prefix."_links WHERE uid=$userid AND catid=$catid ORDER BY name");
    			while ($row = $db->sql_fetchrow($sql)) {
    
    $name = $row['name'];             
    $change = array("æ", "ø", "å", "Æ", "Ø", "Å");
    $change_to = arraa("æ", "ø", "å", "Æ", "Ø", "Å");             
    $name = str_replace($change, $change_to, $name);
    }
    PHP:
    How can I set this as default for every record, mayby in my config file?!?
     
    jmansa, Oct 19, 2008 IP
  2. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #2
    Do something like:

    while ($row = $db->sql_fetchrow($sql)) {

    $name = change_it($row['name']);
    }

    function change_it($name){
    $change = array ("æ", "ø", "å", "Æ", "Ø", "Å");
    $change_to = arraa("æ", "ø", "å", "Æ", "Ø", "Å");
    $name = str_replace($change, $change_to, $name);
    return $name;
    }

    Put that function code in some config/function file.
    regards :)
     
    JEET, Oct 19, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    rohan_shenoy, Oct 19, 2008 IP
  4. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Arh... But I want a solution that makes the str_replace nomatter what the table is and nomatter what the field is... If ever I select something and it has a"æøåÆØÅ in it it should be replaced.
     
    jmansa, Oct 19, 2008 IP