Greaser9780 Posted October 24, 2007 Share Posted October 24, 2007 Here is what I have: $regexp = "<img\s[^>]*alt=(\"??)([^\" >]*?)\\1[^>]*>"; if(preg_match_all("/$regexp/siU", $input, $img, PREG_SET_ORDER)) { foreach($img as $alt){ echo "$alt[2] <br />"; }} I am a reg expression noob. This presents empty results. Can anyone find the error? Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/ Share on other sites More sharing options...
PHP_PhREEEk Posted October 24, 2007 Share Posted October 24, 2007 Before going through all of that expression logic, can you enlighten us on what you're trying to accomplish? The bigger picture, that is... there might be a much easier way to get the end result you want. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/#findComment-376726 Share on other sites More sharing options...
Greaser9780 Posted October 24, 2007 Author Share Posted October 24, 2007 I'm in the midst of building a search engine. I am going to rank sites for each search on things like % of query words to total words for various groups(alt text, description words, title, keywords) and so on. I did however get the following to work: $regexp = "<img src=\"(.*)\" alt=\"(.*)\">"; if(preg_match_all("/$regexp/siU", $input, $img, PREG_SET_ORDER)) { foreach($img as $alt){ $alt_words = adv_count_words($alt[2]); echo "$alt[2] - $alt_words<br />"; So far I can get the words and word count for the following: title meta description meta keywords link text link href heading text bold text underlined text img alt text Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/#findComment-376731 Share on other sites More sharing options...
Greaser9780 Posted October 24, 2007 Author Share Posted October 24, 2007 Now I'm starting to wonder how to put it all in the db. Since the links, alt text,headings, and bold type are all listed by line. I hate to input it with a foreach loop since this will cause many small queries, but maybe this is better than one ginormous query. Then there is the problem when a search is performed. How exactly should the user query to keyword % get checked? 1. Check for all keywords if all are found what is the percentage if all are not found break string into individual words and check for % or 2. Break user query into individual words and check percentage this way? Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/#findComment-376746 Share on other sites More sharing options...
SammyGunnz Posted October 24, 2007 Share Posted October 24, 2007 This should work... <?php preg_match_all('/\<img .* alt=\"([aA-zZ]+)\"/',$str, $imgalt); print_r($imgalt[1]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/#findComment-376747 Share on other sites More sharing options...
Greaser9780 Posted October 24, 2007 Author Share Posted October 24, 2007 Thank you. That's pretty much what I ended up using. Quote Link to comment https://forums.phpfreaks.com/topic/74534-trouble-getting-alt-text-with-regular-expression/#findComment-376748 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.