Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Some Php help

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
Hi. I want to be able to take a string given to me and see if it has "http://" on the front of it. If it dosen't, I want to add http:// to the front. How would I go about finding if the string starts "http://"???

Thanks
Tom
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PoorDoggie said:
Hi. I want to be able to take a string given to me and see if it has "http://" on the front of it. If it dosen't, I want to add http:// to the front. How would I go about finding if the string starts "http://"???

Thanks
Tom


um...
PHP:
$check = explode("http://", $string,2);
if ($check[0] == "http://")
{
 // http:// is the first thing on string
} else
{
$new_string = "http://".$string;
}
 
0
•••
or you could do it in a single line :)

if (!strpos($string, "http://")){$string="http://".$string}
 
0
•••
Amnezia said:
or you could do it in a single line :)

if (!strpos($string, "http://")){$string="http://".$string}

oh cool thanks for telling me that lol
 
0
•••
well its always good to conserve processing power and memory
 
1
•••
Amnezia said:
or you could do it in a single line :)

if (!strpos($string, "http://")){$string="http://".$string}
This dosen't work. If I put in http://url.com it turns out as http://http://url.com
 
0
•••
0
•••
could I do:
PHP:
if(substr($string, 0, 7) != "http://"){$string = "http://".$string;}

Done, thanks for your help!

Hey, check out the script it was for: http://beta.6yd.net/shorturl

Good night
 
Last edited:
0
•••
1
•••
rep added for your help! :)
 
0
•••
i know what the problem is, this will work

if (strpos(" ".$string, "http://")<1){ $string="http://".$string;}

because php is a ghey langauge the return code for a boolean false happens to be a zero
 
0
•••
thanks, but I have fixed it already! :) Also, that finds "http://" in the middle of a string. if it is a redirect script and a user puts in "www.mysite.com/script.php?url=http://google.com&something=somethingelse" then that script will allow it. My script however will see if the string starts with http!

Thanks
 
0
•••
try putting this in .htaccess
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com [NC]

RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
 
0
•••
wackyjoe said:
try putting this in .htaccess
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com [NC]

RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Hi, I have heard about mod_rewrite already. What does what you posted do? Where do I put the .htaccess file?


Thanks
Tom
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back