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...
: [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
[/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...
[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
[/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
'; // 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]
'; // 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?
'; // 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
'; // 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]
Comments
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.
:
: 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
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]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
:
: 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
$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]
: $input = '
some text
: $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?
: : $input = '
some text
: : $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
$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]