cmb Posted October 11, 2012 Share Posted October 11, 2012 This is the first part of the search script and i was doing some debuging and i cant figure out why this code if( !($fd = fopen($url,"r")) ){ die( "Could not open URL!" ); } while( $buf = fgets($fd,1024) ) { /* Remove whitespace from beginning and end of string: */ $buf = trim($buf); /* Try to remove all HTML-tags: */ $buf = strip_tags($buf); $buf = preg_replace('/&\w;/', '', $buf); /* Extract all words matching the regexp from the current line: */ preg_match_all("/(\b[\w+]+\b)/",$buf,$words); print_r($words); } doubles each associate array like this Array ( [0] => Array ( ) [1] => Array ( ) ) Array ( [0] => Array ( [0] => It [1] = > was [2] => November ) [1] => Array ( [0] => It [1] = > was [2] => November ) ) When I would expect this Array ( [0] => Array ( ) ) Array ( [0] => Array ( [0] => It [1] = > was [2] => November ) ) Quote Link to comment https://forums.phpfreaks.com/topic/269330-site-search-help/ Share on other sites More sharing options...
requinix Posted October 11, 2012 Share Posted October 11, 2012 [0] is the entire string matched, [1] is the first capture group. You know, what you get when you surround something in parentheses... Quote Link to comment https://forums.phpfreaks.com/topic/269330-site-search-help/#findComment-1384377 Share on other sites More sharing options...
cmb Posted October 11, 2012 Author Share Posted October 11, 2012 Thank you so much im new to regex so i would have never even thought about that Quote Link to comment https://forums.phpfreaks.com/topic/269330-site-search-help/#findComment-1384380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.