SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expression For Search Functionality

    I am implementing a search functionality for some static pages. My Content is in p tag's, span, div, li's. If I search a word which is in p tag then it get searched but except that non of the word get searched. Below is the regular expression which I am using:

    preg_match_all("/\<p\>(.*)".$_GET['s']."(.*)\<\/p\>/i", $contents, $matches, PREG_SET_ORDER);

    I want such a regular expression which will search all the words no matter it is in p tag, span, div or li. it should get searched.

    Can someone help?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    So.. just find the words, huh.
    $find = str_replace(" ","|",urldecode($_GET['s']));
    preg_match_all("~.*?".$find.".*?~i");
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •