Detect link type

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 8, 2011   (RSS)

Hi Guys.

I have a text field "link" where users will enter an absolute or relative URL. ie. /about.php or http://www.google.com

Is there a way that I can say;

<?php if ($record['link'] starts with "http://): ?> ...this code
<?php elseif ($record['link'] starts with "www): ?> ...this code
<?php else: ?> ...this code

it could also be used for file types... ie. contains .PDF etc
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Detect link type

By robin - September 8, 2011 - edited: September 8, 2011

Hey Tim,

I think you'll find this function usefull:
http://php.net/manual/en/function.substr.php

For example, your first if would look something like:
if("http://" == substr($record['link'],0,7))

Hope that helps,
Robin
Robin
Programmer
interactivetools.com