What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » php, preg replace help

Pages: (2): « First [ 1 ] 2 » Last »
php, preg replace help
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. php, preg replace help
I'm making a bookmarks feature for my website, and I got the cookie system and all already working, but when users forget to put a http:// before the link, it will point to my server and make the link useless.

Now I want to make a system that checks the links before they get submitted, and add a http:// if it's missing.

Now i'm thinking that I can use preg replace to do this, but I really don't understand how to use it.

If someone can make a simple sample for me and show me a good tutorial to use preg replace I can get on with my project :).

The php.net page about the function is really lacking good explanation.

TIA
[Image: 1-0.png]
             
10-23-2005 11:17 PM
Profile PM Web Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: php, preg replace help
You better use substrings for that... tbh
10-23-2005 11:23 PM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php, preg replace help
substrings? I'm sorry i'm a php n00b :P
[Image: 1-0.png]
             
10-23-2005 11:24 PM
Profile PM Web Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
21 / Other / Flag
Joined: Jul 2003
RE: php, preg replace help
psuedo..

code:
if left(URL, 7) != "http://" then
URL = "http://" & URL
end if


thats how i would do it...

in php thats something like..

code:
$pos = strpos($URL, "http://");

if ($pos === false) {
   $URL = "http://". $URL . "";
} else {
   echo "its there :D";
}


This post was edited on 10-23-2005 at 11:49 PM by Stigmata.
10-23-2005 11:24 PM
Profile PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php, preg replace help
Ah, thanks a bunch :)

I'm trying substr and that idea of stigmata :)

EDIT: OMGWTFBBQ

I managed to break my script :S

It's gonna take some time to get it working again, but I believe your script is working stigmata, thanks for that.

This post was edited on 10-24-2005 at 12:15 AM by Ezra.
[Image: 1-0.png]
             
10-23-2005 11:32 PM
Profile PM Web Find Quote Report
brian
Senior Member
****

Avatar

Posts: 819
Reputation: 43
– / Male / –
Joined: Sep 2004
RE: php, preg replace help
If you www.pastebin.com'd it.. we could help.
10-24-2005 01:10 AM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php, preg replace help
nah, already found it, I made a function and used a return but that caused the rest of the function to stop executing, so I changed it a little :)

And that code from stigmata works great :)

This post was edited on 10-24-2005 at 12:50 PM by Ezra.
[Image: 1-0.png]
             
10-24-2005 12:47 PM
Profile PM Web Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
21 / Other / Flag
Joined: Jul 2003
RE: php, preg replace help
:banana:

good to know i can still code :)
10-24-2005 01:05 PM
Profile PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: php, preg replace help
What if I enter this link:

https://www.thisisasafesite.com

It'll be:

http://https://www.thisisasafesite.com

You'd better do:

code:
if (!preg_match("/^[a-z]+:\/\//i", $URL) {
   $URL = "http://". $URL;
}

Should be something like that I think...

This post was edited on 10-24-2005 at 01:24 PM by J-Thread.
10-24-2005 01:24 PM
Profile E-Mail PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php, preg replace help
I guess that will also allow me to use other protocols like ftp, thats good :)

But could you gice me something that explains that "/^[a-z]+:\/\//i"
So I don't have to ask for it next time :D
[Image: 1-0.png]
             
10-24-2005 02:28 PM
Profile PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On