parsing array string to remove "http" from URL

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Compie
Forum Newbie
Posts: 2
Joined: Wed May 28, 2008 8:36 pm

parsing array string to remove "http" from URL

Post by Compie »

Hi,

I have an array value which stores URLs which I print to the page.
It is currently printing the full URL incl. the "http://" part. I would like to strip this off when it displays the URL.
Here is the code:

Code: Select all

<a href="<?php echo $fieldsObjects['field_website']->data; ?>" target="_blank">
<?php echo $fieldsObjects['field_website']->data; ?>
</a>
Can anyone get me started on how to parse the 2nd line so that it strips off the leading part of the URL?

I would be greatly appreciation of this idea.

TIA,

Compie
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: parsing array string to remove "http" from URL

Post by GeertDD »

Code: Select all

substr($str, strpos($str, '://') + 3);
or

Code: Select all

preg_replace('~^https?://~i', '', $str);
Compie
Forum Newbie
Posts: 2
Joined: Wed May 28, 2008 8:36 pm

Re: parsing array string to remove "http" from URL

Post by Compie »

Like that 2nd one!
tnx.
Post Reply