Friday 15 June 2012

PHP - Echo array value foreach array count -



PHP - Echo array value foreach array count -

i have next php code

$businesswebsite = 'http://www.times.hello.com.uk/articles/view/20.141013/local/police-killer.gets-10-more-months-over-drugs.539550'; $host = parse_url($businesswebsite, php_url_host ); $parts = explode( '.', $host); //$parts = array_reverse( $parts ); $domain = $parts[1].'.'.$parts[2].'.'.$parts[3].'.'.$parts[4]; print_r($parts); echo $domain;

this echo's times.hello.com.uk made of 4 parts

array ( [0] => www [1] => times [2] => hello [3] => com [4] => uk )

let domain $businesswebsite = 'http://www.times.com.uk/articles/view/20.141013/local/police-killer.gets-10-more-months-over-drugs.539550';

it echo times.hello.com.. end 2 dots @ end.

if domain $businesswebsite = 'http://www.times.com/articles/view/20.141013/local/police-killer.gets-10-more-months-over-drugs.539550';

it echo times.com... end 3 dots @ end.

how go solving problem?

i want remove double , triple dots @ end.

use php's trim , implode.

as said want remove double , triple dots @ end of string:

$domain = implode('.',$parts); $domain = trim($domain, '.'); print $domain;

php arrays

No comments:

Post a Comment