Jump to content

Finding sub strings


Perad

Recommended Posts

I think i might need to use preg_replace. However I have never used it before and can't workout how to find the following.

 

This is my string..

Call Out Fee for 10:00 on 20/8/2007

 

What I need is for this string to be reduced to 10:00 and 20/8/2007. These values would preferably be in an array. Could someone give me a hand with this please.

Link to comment
Share on other sites

Hi,

 

is the string size and position constant?

 

If so I would do something like:

 

  
  $string = "Call Out Fee for 10:00 on 20/8/2007";
  array[1] = substr($string, 17, 5);
  array[2] = substr($string, 26, 9);

 

As i say this will only work if the string is consistant in length and there is probably a better way  :D

 

Cheers

Dave

 

Link to comment
Share on other sites

sasa would be faster than ProjectFear

 

 

as were all doing one heres mine

 

<?php
$data = "Call Out Fee for 10:00 on 20/8/2007";
if (preg_match('%(\d+:\d+)[\D]*([\d/]{8,10})%si', $data, $regs))
{
echo $regs[0];
echo "<br />time is ";
echo $regs[1];
echo " date is ";
echo $regs[2];
}

?>

 

NOTE:

$regs[0] is the full string

$regs[1] is the time

$regs[2] is the date

 

Link to comment
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.