Getting the urls and only the urls with ereg

Trying to match any weird and wonderful url or hyperlink in a piece of text is fun – I found “help” all over the place, but none of them quite got it all –  This was clear when using the eccentric holidays calendar for a test case in my ical upcoming events list

Eventually with the help of “The Regex Coach” (thank you very much) to test we (I’m a gemini) settled on the following code.  It will find any of the following links, while excluding any text already hyper linked.

Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donner, Blixen….

The code handles urls with dashes, underscores, trailing slashes, suffixes, query strings ? and ampersands &, equal signs.  It rejects urls with other funny characters.

We want regular expressions to replace EXPR in the formula below:

$text = ereg_replace( EXPR , "<a href=\"\\0\">\\0</a>", $text);

http or https or ftp type urls:

"[a-zA-Z]+://([.]?[a-zA-Z0-9-])*([/]?[a-zA-Z0-9_-])*([/a-zA-Z0-9?&#\._=-]*)"

and another for www urls (at start of line or after space)

“(^| |\n)(www([.]?[a-zA-Z0-9-])*)([/]?[a-zA-Z0-9_-])*([/a-zA-Z0-9?&#\._=-]*)”

These two lines of code deals with the following examples:

  • http://smarmycarny.com/get-over-it-day
  • http://www.smarmycarny.com/get-over-it-day
  • www.smarmycarny.com/get-over-it-day
  • www.smarmycarny.com/get_over_it-day/
  • www.smarmycarny.com/get-over-it-day/test.htm
  • www.smarmycarny.com/get-over-it-day/test.php?somequery&yes=true
  • www.smarmycarny.com/get-over-it-day/test.html#bot-tom

Strange urls are ignored or dealt with accordingly. See example:

Demo of ignored and selected text
Demo of ignored and selected text

Disaster planning… why you need to practise recovering

It happens!

Flood

In my second job, one of our clients got flooded: the computer room was below sea level (?) and there was a canal not far way – maybe it rained a lot, maybe the canal broke it’s banks. I don’t know but what I remember is: When the waters were rising and people left, they put their printouts and spare disks and other pseudo precious stuff that they weren’t carrying on top of the filing cabinets.

One programmer was well protected, he had a backup on the front seat of his car, a backup on the filing cabinet and a backup on his desk at home:

  • multiple copies    
  • offsite    

And then..

  • The waters rose above the filing cabinets and it was very muddy…
  • The car park was higher but not high enough
  • The dog’s tail knocked a coffee cup over

It’s the impact you need to worry about, not the likelihood.

These days anything is possible.

These have all happened within the last couple of months either to us or our friends:

PC and backup both fail

For a horrible few days I though I had lost my Pc and my backupdrive.  Yes I had a third backup but I had got slack… it was out of date.  Managed to recover the PC – thank goodness – I found out how expensive thoise hard drive recovery people are – your data has to be really serious.

Extended power failure – all your stuff is electronic

  • and your phone is old and does not have many contacts in it

Your laptop gets stolen

  • along with the expensive application’s dongle
  • within months of purchasing it and you are so busy with your new business

Your laptop gets unpredictable

  • not so bad you replace it, bad enough that you spend days waiting for Dell engineers to replace this, that and the other
  • you have not integrated with the cloud, so you are having problems getting at emails, contacts etc

back a bit more….

Your facebook account gets trashed

  • I don’t remember the details but somehow this theatrical arty friend pretty much was running her electronic life through facebook

Your website gets hacked

  • I helped a friend clean up their web, and in researching it I discovered many sites who did not even know that they had been hacked.

You accidentally deleted (?) your outlook contacts

  • you have no backups at all!!

You only had a webmail account, which got deleted…

  • You leave the employment of a small company who finally get around to cleaning up your email account…..Luckily all were on good terms and there was a backup.

The power station has not figured out how the big glowy thing works

  • The province continues to have rolling unpredictable blackouts…
  • my smart cookie of a sister whose livelihood depends on her pc had already got herself with her own UPS and yoga breathing to deal with the scheduled blackouts happening at unscheduled times.

We all live with the possibility of disaster of one kind or another.  We insure our houses, our cars, our bodies.  We lock our doors (most of us anyway, some of us drop our car keys in the front yard … the car gets stolen and the insurance company investigates for fraud!).

We need to insure our electronic lives too – our memories, our financial records, our network….

We have fire drills, so…

  • Do you now how to restore from your backups?
  • Are the backups actually backing up everything you think it is?
  • Is your data safe? as in encrypted, password protected …..
  • do you have offsite/ remote access
  • ,…

At the very least make a page of what is important to you and what you would do if it is lost, damaged or stolen.

See next posts for an example backup plan

Why horizontal scrollbar?

You think your html and css looking good and then you notice – a horizontal scrollbar when the site should not need to scroll!

Reasons for a scrollbar

They all come down to the same thing – the browser thinks it needs a bit more space…… Some situations that may trigger this perception or actual need:

  • 100% width, plus some padding makes it more than 100%!
  • 100% width, plus Italics : IE has to make it just that bit wider for the italics, perhaps forcing a horizontal scrollbar.
  • <pre> preformatted code that is wider than it’s containing element.

Using overflow just hides the problem

A number of sites will advise using the overflow property to get rid of it. That may well bandaid it and admittedly it is a quick fix.