Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.