Jump to content

Archived

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

bundy

String trim and date problem

Recommended Posts

Hi,
I'm using a referral script on my page and it looks like this
[quote]
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
[/quote]

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)
[code]'LAST' => create_date($board_config['default_dateformat'], $row['referrer_lastvisit'], $board_config['board_timezone']))
[/code]

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

Share this post


Link to post
Share on other sites
You can also use plain str_replace()
[code]<?php
$str = 'www.test.com';
echo str_replace('www.','',$str);
?>[/code]

Ken

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote author=kenrbnsn link=topic=100188.msg395090#msg395090 date=1152623383]
You can also use plain str_replace()
[code]<?php
$str = 'www.test.com';
echo str_replace('www.','',$str);
?>[/code]

Ken
[/quote]

that worked perfectly! many thanks to everyone!

Share this post


Link to post
Share on other sites

×

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.