Hi,
I have a scalar variable, "$url" that may or not contain "http://" in
front of it. If it is not there, I'd like to add it. Unfortunately,
this code isn't working for me with PHP 4.
if (strpos(strtolower($url), "http://") != 0) {
$url = "http://$url";
} // if
How can I correct?
Thanks, - Dave 3 2234 la***********@zipmail.com wrote: I have a scalar variable, "$url" that may or not contain "http://" in front of it. If it is not there, I'd like to add it. Unfortunately, this code isn't working for me with PHP 4.
if (strpos(strtolower($url), "http://") != 0) { $url = "http://$url"; } // if
How can I correct?
if (strpos(strtolower($url), "http://") !== false) {
$url = "http://$url";
}
Read the Manual, it's all there: http://www.php.net/strpos
Cheers,
NC
NC wrote: la***********@zipmail.com wrote: I have a scalar variable, "$url" that may or not contain "http://" in front of it. If it is not there, I'd like to add it. Unfortunately, this code isn't working for me with PHP 4.
if (strpos(strtolower($url), "http://") != 0) { $url = "http://$url"; } // if
How can I correct?
if (strpos(strtolower($url), "http://") !== false) { $url = "http://$url"; }
It's just a pity for relative links, other protocols ( https://, ftp://, even
mailto:, all extremely valid). Then again, that wasn't the op's question...
I'd:
if(preg_match('"^(https?://|ftp://|mailto:|\.{0,2}/|smb://|file://|s?news:|l
dap(i|s)?:|gopher:|nntp:|telnet:|mms:|ssh:)"si', $url)<1) $url =
'http://'.$url;
I'm still forgetting a lot of other possibilities though...
Grtz,
--
Rik Wasmus
Rik: if(preg_match('"^(https?://|ftp://|mailto:|\.{0,2}/|smb://|file://|s?news:|l dap(i|s)?:|gopher:|nntp:|telnet:|mms:|ssh:)"si', $url)<1) $url = 'http://'.$url;
I'm still forgetting a lot of other possibilities though...
Forget about particular schemes and match scheme names (plus colon)
in general:
`^[a-z][a-z\d+.-]+:`i http://www.ietf.org/rfc/rfc3986.txt :3.1
--
Jock This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Manjesh Gowda |
last post by:
Hi all,
I am maintaing a persistent HTTP connection using the "HTTP
CONNECT" method , this works fine for many proxies like Squid, ISA ,
etc. But the iPlanet proxy disconnects the conneciton...
|
by: sinister |
last post by:
After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?
For example, if there is a page
http://www.domain1.com/page1.html...
|
by: ryan.fairchild |
last post by:
Ok I basically am creating a container for a bunch of other <div> tags.
But I want to make four jpegs/gif/whatever that goes in each corner so
they look rounded.
I thought this is how I would do...
|
by: Studio P.M. |
last post by:
Having built successfully my first HTTP Module prototype (as for Q307996
- HOW TO: Create an ASP.NET HTTP Module ...) without really understanding
what I've done, now I kindly ask this community...
|
by: Joeyej |
last post by:
Hi -
I'm trying to move/use a web form (containing some javascript field
checks) previously hosted on a Windows 2000 server. However, the FORM
METHOD="post..." command in the form (shown below)...
|
by: Yeah |
last post by:
Is it absolutely necessary to include "http://" in an A HREF hyperlink?
Would it be wise to remove this from one's Links page, just to save code?
|
by: Lee Roth |
last post by:
I am testing a web app that links to user defined URLs. I want the link
to be the exact text the user provided but I can't seem to get rid of
the "http://localhost" prefix in the link. Note that I...
|
by: jjw92 |
last post by:
I've been banging my head against the wall with this one for a couple days so I'm hoping someone has some ideas. I have a web service that I created that is called by a .NET class library (which in...
|
by: Tamer |
last post by:
Hi!
Is there a way to change the protocoll type through Javascript without
reloading (or making a request from the webserver) via Javascript?
for example:
http://mydomain.com...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |