-
Posts
13 -
Joined
-
Last visited
Contact Methods
-
Website URL
http://syndikut.org
Profile Information
-
Gender
Male
noidea's Achievements

Newbie (1/5)
0
Reputation
-
How to find 2 or more words in a string with preg_match?
noidea replied to noidea's topic in Regex Help
ok i think using joshs code i figured it out function SplitQuery($this_query, $to_search) { $searchTerms = explode(" ", $this_query); $allMatched = 1; foreach ($searchTerms as $searchTerm) { if ( preg_match('/'.$searchTerm.'/i',$to_search) == false ) { $allMatched = 0; } } return $allMatched; } so while looping through my files i just need to do if(SplitQuery($this_query, $to_search) == 1) { $data_to_display[] = $news_headline."|".$news_content; //This will collect only data that contains words typed in $this_query } cheers for helpin, i just cant believe something so simple has to be so complex lol- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How to find 2 or more words in a string with preg_match?
noidea replied to noidea's topic in Regex Help
from my understanding, as im using a while loop i need to create a function based on the code that josh posted and thats my problem lol - i dont understand the logic behind it as it was not explained - im grateful for the help but its only useful if it explains how it helps I get i need to break each word up the user entered but then i dont know what do to next to check that ALL the words (needles) exist in a given haystack- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How to find 2 or more words in a string with preg_match?
noidea replied to noidea's topic in Regex Help
yeah i get the foo and bar thing lol I just dont understand how the code helps my scinario (posted above) or how to inplemtent it.. i have tried but i dont get the results i need Im still getting the results based on "or" so if "foo" or "bar" then results where found but i dont need that I need AND so if "foo" and "bar" exists then boom! job done! I cant believe i cant even find a simple solution for this- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How to find 2 or more words in a string with preg_match?
noidea replied to noidea's topic in Regex Help
Hi thanks for helpig but i really dont understand your code... I have tried putting the users entered search words in an array which works but for me this basically does the same as the "or" it outputs results $text_to_search if 'foo' or 'bar' are found where i only want it to out put if both words exists Also what do the '~' operators mean? im sure its my fault its not working as im trying to get it to work within my script ... im basically having to loop through files while this is goin on example: function SplitQuery($this_query) //Function to return each search word pipe operator for "or" for preg_match { $all_words = explode(" ", $this_query); foreach($all_words as $val => $word) { $return = $return . $word."|"; } $to_return = trim($return, "|"); return $to_return; // Will return "each|keyword|seperated" } $query = $_POST['q']; //Users posted search words $search_str = SplitQuery($query); //Get each search word from phrase $news_path = "news"; // Folder where files are stored $dir = opendir($news_path); //Open news Folder while (false !== ($file = readdir($dir))) { if ($file != "." && $file != "..") { $release_file = trim($file); $file_path = $news_path."/".$file; if(!is_dir($file_path)) //Make sure file is not a sub dir { $file_contents = file_get_contents($file_path); //Get the contents of each file $explode_parts = explode("|",$file_contents); //Put contents in array $news_headline = $explode_parts[1]); //News Headline $news_content = $explode_parts[2]); //News Main Content if(preg_match("/$search_str/i", $news_headline." ".$news_content)) //Search to see if user { $search_data[] = $news_headline."|".$news_content."|"; } } } } closedir($dir); //Close Dir the above works but only on an OR basis where i need to check to see if ALL entered words are in section of text Sorry im not very good at explaining myself well lloll- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How to find 2 or more words in a string with preg_match?
noidea replied to noidea's topic in Regex Help
hi thanks for the reply This wont work for my needs as the amount of words enterd will vary... imagine a search scenario where the user can enter multiple words- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
hay there How can i check for say 2 or more words in a string... Now I know this checks for 2 words on a "OR" basis if(preg_match("/$findthis|$this/i", $text_to_search)) { //do something } So this ill check to see if the $text_to_search contains either $findthis or $this but i need it to check with the "and" operator - so for example.. search $text_to_search for $findthis and $this how can i do this? many thanks
- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
Sorry but if by "proper database" you mean a SQL database, I have never worked with one so i have no idea about how they work It is something I may look into in the future
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with:
-
the pagination links ive already got for the code above.. my main problem is getting the results out in the table thanks
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with:
-
i really stuck lol, been tryin to work it out all night lol I just dont even know where to start with the table and how to create the dynamic columns If you could help id be very grateful, oh master lol
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with:
-
DOHH!! so sorry lol The question is i guess, how can this be done.. im really stuck on this cheers
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with:
-
Hi I have a list of youtube videos in a flat file database. I would like to print a thumbnail of these videos out to the end user in a table. The results need to have pagination as well as a dynamic table so i can display say 3 rows and 3 columns per page. The column amount will also need to be adjustable in case i wish to change the columns from 3 to 4 for example: $video_file_data[]; //This is the array in which all video info will be stored $start = $_REQUEST['start']; //pagination setting $videos_per_page = 9; //Show 9 Vids per page $table_colums = 3; //Amount of columns needed to display results per page $num = count ($video_file_data); //Number of lines in data array $max_pages = @ceil($num / $videos_per_page); //Maximum number of Pages $cur = @ceil($start / $videos_per_page)+1; for($i=$start;$i<min($num,($start+$videos_per_page)+0);$i++) { list($date_added, $video_title, $youtube_url) = explode('|', trim($video_file_data[$i])); // <--- Table needs to go } The info stored in $video_file_data[] would look something like this: date 1."|".title 1."|".youtube url 1 date 2."|".title 2."|".youtube url 2 date 3."|".title 3."|".youtube url 3 date 4."|".title 4."|".youtube url 4 Many thanks for the help
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with: