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
https://forums.phpfreaks.com/topic/65672-finding-sub-strings/
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
https://forums.phpfreaks.com/topic/65672-finding-sub-strings/#findComment-327954
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
https://forums.phpfreaks.com/topic/65672-finding-sub-strings/#findComment-327983
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.