help about string matching

Discussion in 'PHP' started by beven, Jun 18, 2012.

  1. #1
    hi all
    I have following code to search a string from a big string. I am taking both ones from users. but i have a problem that i want to bold the match string in answer. For example...

    following code give answer that it show the string where it is matched & also show rest of string as well. I want to bold the matched string & rest of string in normal view..

    Any suggestion will be appreciated. Following code is good u can check.
    Thanks




    <form method="post" action="dublicate_check.php">

    <span>Enter Data from Search</span></br>

    <textarea name="textarea1" style="resize:none; width:550; height:100;" >
    </textarea></br>
    <span>Enter Data to Search</span></br>
    <textarea name="textarea2" style="resize:none; width:550; height:100;" ></textarea></br>
    <input type="submit" value="submit" />
    </form>

    <?php

    if(isset($_POST["textarea1"]) and $_POST["textarea1"] !="")
    {
    if(isset($_POST["textarea2"]) and $_POST["textarea2"] !="" ){

    $v=$_POST["textarea1"];
    $serac=$_POST["textarea2"];


    $anc=strstr($v,$serac);




    echo "<b>Data from Searched</b></br></br></br>".$v."</br></br>";
    echo "<b>Data which is Searched</b></br></br></br></b>".$serac."</br></br>";

    echo "<b>Here is dublicate string with rest of one</b> <br><br> ".$anc ."</br>";







    }//end of if statement
    }//end of if statement
    ?>
     
    beven, Jun 18, 2012 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    here you go
    
    <?php
    
    $outputtext = str_replace($serac,'<b>'.$serac.'</b>',$v);
    
    
    ?>
    
    PHP:
     
    stephan2307, Jun 18, 2012 IP
  3. beven

    beven Well-Known Member

    Messages:
    483
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Thanks i got my answer... it works
     
    beven, Jun 18, 2012 IP