Jump to content


Photo

String trim and date problem


  • Please log in to reply
4 replies to this topic

#1 bundy

bundy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 July 2006 - 12:56 PM

Hi,
I'm using a referral script on my page and it looks like this

11/07/06, 12:48 www.blablabla.com
11/07/06, 12:31 www.blablabla.org
11/07/06, 12:27 www.blablabla.be
11/07/06, 12:24 www.blablabla.nl
11/07/06, 12:21 www.blablabla.be
11/07/06, 12:18 blablabla.com
11/07/06, 12:13 www.blablabla.com
11/07/06, 12:03 www.blablabla.be
11/07/06, 12:00 blablabla.be
11/07/06, 12:00 www.blablabla.be


is there a way to remove the www. on the referrals (that have one of course).
So in other words I need a script that deletes a certain follow up of chars (in this case www.) in a given string.

have another question about the date this time.
it's generated by this code (it's a phpbb forum)
'LAST' => create_date($board_config['default_dateformat'], $row['referrer_lastvisit'], $board_config['board_timezone']))

is it possible to drop the date and only display the time?
thanks in advance
Bundy

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 11 July 2006 - 01:06 PM

<?php
$string = "www.test.com";
echo substr_replace($string, '', 0,4);
?>

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 01:09 PM

You can also use plain str_replace()
<?php
$str = 'www.test.com';
echo str_replace('www.','',$str);
?>

Ken

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 11 July 2006 - 01:12 PM

There is no universial rule to strip those www. but you can write a function.

it's simple and safe:

function stripWWW($str)
{
   $pattern = substr($str, 0,4);
   if (strcasecmp($pattern,'www.') == 0)
       return substr($str,4);
   else return $str;
}

echo stripWWW('www.google.com'); // echo google.com
echo stripWWW('google.com'); // echo google.com
echo stripWWW('www.www.net'); // echo www.net
Life's too short for arguing.

#5 bundy

bundy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 11 July 2006 - 01:13 PM

You can also use plain str_replace()

<?php
$str = 'www.test.com';
echo str_replace('www.','',$str);
?>

Ken


that worked perfectly! many thanks to everyone!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users