ellipsis Posted July 6, 2008 Share Posted July 6, 2008 I'm learning PHP from a book and am having difficulty with regular expressions. <?php $quote = "Now is the time for all good men to come to the aid of their country."; $count = ereg("(^t)", $quote, $regs); echo $count; echo "<br/>"; echo $regs[0]; echo "<br/>"; echo $regs[1]; echo "<br/>"; echo $regs[2]; echo "<br/>"; echo $regs[3]; echo "<br/>"; echo $regs[4]; echo "<br/>"; echo $regs[5]; echo "<br/>"; echo $regs[6]; echo "<br/>"; ?> What I am trying to do is search the string $quote for all (whitespace-delimited) substrings beginning with a t. The output I am expecting is: 6 the time to to the their but it isn't working. I've spent some time on this function and can't get it to work. My browser (Firefox 2.0.0.15) doesn't even give me an error, it's just a blank page. Am I looking at this function the wrong way? Is there some directive I have overlooked in the INI file? Any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/113464-basic-ereg-question/ Share on other sites More sharing options...
papaface Posted July 6, 2008 Share Posted July 6, 2008 <?php $mystring = 'the'; $findme = 't'; if (strpos($mystring, $findme) == 0) { //do something } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113464-basic-ereg-question/#findComment-582999 Share on other sites More sharing options...
sasa Posted July 6, 2008 Share Posted July 6, 2008 try <?php $quote = "Now is the time for all good men to come to the aid of their country."; preg_match_all("/\st[^\s]*/", $quote, $regs); print_r($regs); ?> Quote Link to comment https://forums.phpfreaks.com/topic/113464-basic-ereg-question/#findComment-583025 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.