search script excludes html tags - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

search script excludes html tags

CrushCrush Posts: 43Member
i was wondering if any of you know a good php search script that searches a table for information but excludes html tags from the text.
i dont want people to rearch for 'img' and get some stupid results and stuff...

Comments

  • Homerun31Homerun31 Posts: 99Member
    [code]SELECT * FROM Table_Name WHERE Test LIKE 'hello'[/code]

    this will search a table and find a word that is like hello in the table. u replace hello with another word. hope this helps.
  • CrushCrush Posts: 43Member
    : [code]SELECT * FROM Table_Name WHERE Test LIKE 'hello'[/code]
    :
    : this will search a table and find a word that is like hello in the table. u replace hello with another word. hope this helps.
    :

    well, i figured it out that far, but the question was different.
    the table_name table test contains something like this

    [code]

    some text

    picture[/code]

    so if a user searched for img, he would get the stupid tag as a result. how to exclude the tag from results? the user only can search the "some text" part and maybe some comments on images...
  • netgertnetgert Posts: 331Member
    [b][red]This message was edited by netgert at 2004-9-7 7:40:47[/red][/b][hr]
    : : [code]SELECT * FROM Table_Name WHERE Test LIKE 'hello'[/code]
    : :
    : : this will search a table and find a word that is like hello in the table. u replace hello with another word. hope this helps.
    : :
    :
    : well, i figured it out that far, but the question was different.
    : the table_name table test contains something like this
    :
    : [code]

    some text

    picture[/code]
    :
    : so if a user searched for img, he would get the stupid tag as a result. how to exclude the tag from results? the user only can search the "some text" part and maybe some comments on images...
    :
    [code]
    $input = '

    some text

    picture'; // the full data
    $pattern = "/<[^>]*>/i"; // match tags
    $replace = ""; // replace with nothing
    $output = preg_replace($pattern, $replace, $input); // do the replacing
    [/code]
    syntax not tested
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]



  • CrushCrush Posts: 43Member
    : [code]
    : $input = '

    some text

    picture'; // the full data
    : $pattern = "/<[^>]*>/i"; // match tags
    : $replace = ""; // replace with nothing
    : $output = preg_replace($pattern, $replace, $input); // do the replacing
    : [/code]
    : syntax not tested
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :

    thank you for the help so far...
    but how to search the $output string? with some php strstr functions?
  • netgertnetgert Posts: 331Member
    : : [code]
    : : $input = '

    some text

    picture'; // the full data
    : : $pattern = "/<[^>]*>/i"; // match tags
    : : $replace = ""; // replace with nothing
    : : $output = preg_replace($pattern, $replace, $input); // do the replacing
    : : [/code]
    : : syntax not tested
    : : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    : :
    :
    : thank you for the help so far...
    : but how to search the $output string? with some php strstr functions?
    :
    strpos()

    a better idea might be to use only one regular expression that will ignore text inside tags
    [code]
    $input = '

    some text

    picture'; // the full data
    $search = 't*xt'; // what to search for

    $search = str_replace(["*", "/"], [".*", "\/"], $search); // common wildcard to regexp "wildcard"
    $pattern = "/(?:<[^>]*>).*".$search."/iU"; // match tags
    if (preg_match($pattern, $input)) { /* we have a match */ }
    // or
    prg_match_all($pattern, $subject, $matches); // see the manual for structure of $matches
    [/code]
    again, syntax/regexp not tested
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Sign In or Register to comment.