String Problem

Discussion in 'PHP' started by Dreads, Apr 17, 2008.

  1. #1
    FIRST PROBLEM SOLVED..

    NEW PROBLEM

    - Now it seems that if it finds "use" inside the word because (beca"use") it would replace it, what should i add? to the existing code to fix it?
    <?php
    
    include 'config.php';
    include 'connectdb.php';
    
    $text = $_POST["text"];
    $query = "SELECT * FROM myqrio";
    $result = mysql_query($query);
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $oldword = $row['word'];
        $newword = $row['replacex'];
        $text = str_replace($oldword, $newword, $text);
    }
    
    echo $text;
    
    include 'connectoff.php';
    ?>
    
    PHP:
    I was thinking maybe.. add a space infront of the string of $oldword ?
     
    Dreads, Apr 17, 2008 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Try this:

    <?php
    
    include 'config.php';
    include 'connectdb.php';
    
    $text = $_POST["text"];
    $query = "SELECT * FROM myqrio";
    $result = mysql_query($query);
    
    $SearchWords = array();
    $ReplaceWords = array();
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    	$SearchWords[] = $row['word'];
    	$ReplaceWords[] = $row['replacex'];
    }
    
    $final = str_replace( $SearchWords, $ReplaceWords, $text );
    echo $final;
    
    include 'connectoff.php';
    ?>
    PHP:
    Brew
     
    Brewster, Apr 17, 2008 IP
  3. Dreads

    Dreads Well-Known Member

    Messages:
    1,884
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    150
    #3
    nopz it didnt work :(
    if u have a msn or something, i can show u the script and stuff -_-
     
    Dreads, Apr 17, 2008 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ?

    
    <?php
    
    include 'config.php';
    include 'connectdb.php';
    
    $text = $_POST["text"];
    $query = "SELECT * FROM myqrio";
    $result = mysql_query($query);
    
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    	$oldword = $row['word'];
    	$newword = $row['replacex'];
    	$text = str_replace($oldword, $newword, $text);
    }
    
    echo $text;
    
    include 'connectoff.php';
    ?>
    
    PHP:
     
    hogan_h, Apr 17, 2008 IP
  5. Dreads

    Dreads Well-Known Member

    Messages:
    1,884
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    150
    #5
    EDIT:

    NEED HELP ON THE SECOND PROBLEM

    Thanks
     
    Dreads, Apr 17, 2008 IP
    hogan_h likes this.
  6. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, try modifying the entry in database und put " use" instead of "use" in 'word' column.
     
    hogan_h, Apr 18, 2008 IP
  7. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Exactly what I do, good call.
     
    phpl33t, Apr 18, 2008 IP