Jump to content

basic ereg() question


ellipsis

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/113464-basic-ereg-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.