Help With PHP Preg_match to search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xmanofsteel69
    New Member
    • Feb 2007
    • 1

    Help With PHP Preg_match to search

    I'm trying to create a search function for my site and I can't ever seem to figure it out. If anybody could help, that would be awesome, because everything I try, I keep getting errors...

    Here's my code so far.
    [PHP]
    <div style='display: none;'>
    <html>
    <head>
    <title>The Movie List</title>
    </head>
    <body bgcolor = black>
    </div>
    <center>
    <img src="moviep.jpg "><br>
    <img name="image" src="image.gif" width="650" height="75" border="0" id="image" usemap="#m_imag e" alt="" /><map name="m_image" id="m_image">
    <area shape="poly" coords="14,2,11 0,2,110,71,14,7 1,14,2" href="http://tjjam4.farvista .net/Home.php" alt="" />
    <area shape="rect" coords="467,0,6 38,71" href="http://tjjam4.farvista .net/Suggest.php" alt="" />
    <area shape="rect" coords="339,2,4 55,71" href="http://tjjam4.farvista .net/The_Movie_List_ Rev.php" alt="" />
    <area shape="rect" coords="126,0,3 23,71" href="http://tjjam4.farvista .net/The_Movie_List. php" alt="" />
    </map>
    </center>
    <form action="Search. php" method="post">
    <table border="0" bgcolor=white cellspacing="5" >
    <tr><td><font color=red>Searc h</font></td><td><input type="text" size="60" name="search"></td></tr>
    <tr><td>&nbsp ;</td><td><input type="submit" value="Send"><f ont face="arial" size="1">&nbsp; &nbsp;Click Send To Continue</font></td></tr>
    </table>
    </form>
    <font color = red>

    <?php


    $Movie = file_get_conten ts('Movies.txt' );
    parse_str($Movi e);

    function title_cmp($a, $b)
    {
    $a_cmp = preg_replace('/^(A|An|The) /', '', $a['Title']);
    $b_cmp = preg_replace('/^(A|An|The) /', '', $b['Title']);

    return strcmp($a_cmp, $b_cmp);
    }



    usort($Movie, 'title_cmp');

    if($_POST['search'] =! '')
    {
    $search = $_POST['search'];

    foreach($Movie as $key =>$val)
    {
    if(preg_match(s trtolower($sear ch), strtolower($Mov ie[$key][Title])));
    {
    echo $Movie[$key][Title].'<br>';
    }
    }

    }

    ?>[/PHP]

    The error I keep receiving is:

    Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in E:\Tyson\wamp\w ww\jedit\Test1\ Search.php on line 49 #
    And that repeats over and over again for each value within my array...

    This is what the file looks like that I'm getting data from:

    Movie[1][Title]=Troy&Movie[1][Genre]=Action / Drama / History /

    Romance&Movie[2][Title]=Mr. and Mrs. Smith&Movie[2][Genre]=Action /

    Comedy / Romance / Thriller
    I have no idea how to get this to work...so any help would be amazing! Thank you so much!
Working...