March 31, 2011
Today seems to be the day for posting useful stuff on the blog. Actually, it’s just so I can quickly useful find bits of code I might need again.
So I’ve a got a web page that displays some text a user has entered that may contain URLs and I’d like them to be displayed as actual hyperlinks.
public string ConvertUrlsToLinks(string msg)
string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
Regex r = new Regex(regex, RegexOptions.IgnoreCase);
return r.Replace(msg, "$1").Replace("href=\"www", "href=\"http://www");
March 18, 2010
“Is a URL a URI?”
“Is a URI a URL?”
“What does URL stand for?”
“What does URI stand for?”
“What does URL mean?”
I’ve been asked so many times I’ve lost count and for the sake of my sanity, I’ve decided to explain their distinquishing marks.
URL – Uniform Resource Locator
URI – Uniform Resource Identifier
Sometimes these achronyms are used interchangably which is almost entirely wrong. Basically a URL is a specific type of URI because it uses specific protocols like http: ftp: and mailto: URI defines a larger, more generalized superset.
Effectively, URL is no longer a valid in technical conversations or documents and you should use URI regardless of how big a pedant you are. A URI describes both the way you access something and it’s designated location.
You may see some explainations where U is defined as Universal. This is wrong and the author is just confused.
So, let’s call the whole thing off.
May 1, 2009
Yesterday I was mainly deploying a new release of php code to a Linux server. Not that it’s a problem, but I normally develop php web application on IIS running on Windows Server just because I know where all the knobs and switches are. VS.PHP from jcx.software is a great add-in for Visual Studio and with the Zend server side debugger it makes an awesome development environment. Sure I could use Eclipse PDT in a similar way for free, but ‘m more productive using Visual Studio; rightly or wrongly, the keyboard shortcuts are now part of my DNA.
I never quite feel comforable using Linux and I’m not sure why. Clearly it’s an excellent OS and I have several embedded boxes which have been running Linux that I’ve never had to reboot. My WRT54G and NSLU2 always perform flawlessly. However, while on my journey home last night I realised what the problem might be. Linux makes my fingers hurt with all the typing I have to do!
Anyway, tip of the day for me was this little gem. I needed to copy the (massive) previous releases directory into my deployment working area and was happily using
cp -r blah blah
Then I started worrying about whether the permissions were being copied. (Ok so I’m happy to admit my perpetual virgin status when it comes to Linux). It was then pointed out to me buried in the directory structure were a raft of symbolic links and using cp would do a deep copy and fill up my server disc space pretty quickly. “Use tar to copy from the current directory to the new one like this”, they said.
tar cBf -.|(cd new_directory && tar xvBf -)
It worked a treat, I feel less like a Linux virgin, but my fingers still hurt.
November 20, 2008
It’s not often I’m impressed with a new soap star – other than Hollyoaks and there’s only one reason to watch that. However, I recently had to integrate a web service client in the web site that displays a list of all the senior level consultants in the company. The website in question is written using php so a php SOAP consumer would be needed. And, as usual, I needed to get it done quickly.
There were a few options:
After some investigation and for various reasons I chose nuSOAP which is staggeringly easy to use. Here’s the code I needed to make it work – and there’s not much of it.
defined('_JEXEC') OR defined('_VALID_MOS') OR die( "Direct Access Is Not Allowed" );
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
$client = new soapclient('http://somewebsite.com/Consultants.asmx?WSDL', true, $proxyhost, $proxyport, $proxyusername, $proxypassword);
$result = $client->call('GetConsultants', array(), '', '', false, true);
$err = $client->getError();
echo '<h2>Error</h2><pre>' . $err . '</pre>';
for ($i=0; $i<sizeof($result["GetConsultantsResult"]["ConsultantDetail"]); $i++)
nuSOAP is particularly easy to debug and display the SOAP request and responses. Incidently, this needed to be incorporated into a Joomla based site which normally means having to write a module or plugin. Yet again I was saved by the Jumi plugin which meant I could just put the php directly into an Article. Couldn’t be simpler. You can see it working here http://www.candelamedia.co.uk/index.php/candela-consulting/our-consultants