andrewducker: (overwhelming firepower)
[personal profile] andrewducker
I have user input for a URL field. I want them to be able to enter anything from "http://andrewducker.wordpress.com/xmlrpc.php" to "andrewducker.wordpress.com" and be able to end up at the same end point.

I've wasted a couple of hours messing around with the various constructors for URL and not got to anywhere satisfactory, should I just do string checking and construct it myself?

I should make it clear - I always want the /xmlrpc.php bit to be what's on the end of the URL, that's a Wordpress standard, so I don't need to do any complex discovery. I just need to append that if it's not there.

I was hoping that someone would have written a class that could append bits of URLs together, but the basic stuff in the built in URL class doesn't quite cut it.

Date: 2011-11-24 09:52 am (UTC)
drplokta: (Default)
From: [personal profile] drplokta
I think you'll need to add an (s)* to cope with the https possibility.

Date: 2011-11-24 09:56 am (UTC)
From: [identity profile] pozorvlak.livejournal.com
I for one find your use of * in place of ? surprising. A hangover from pre-PCRE regexes?

Date: 2011-11-24 10:01 am (UTC)
drplokta: (Default)
From: [personal profile] drplokta
I just simplify matters for myself by not bothering to remember what ? does unless I actually need it. In this case, it doesn't really matter if something like "http:http://" gets stripped off the beginning or "xmlrpc.phphp" gets stripped off the end, so I didn't bother. If it was important to match only a single occurrence, I'd look it up again. Yes, most of the *s can probably be ?s, except in the "(\/)*" bit where * is needed.

October 2025

S M T W T F S
    1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
262728293031 

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 26th, 2025 03:40 am
Powered by Dreamwidth Studios