TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Handling Commas in image titles (http://www.talkphp.com/absolute-beginners/6060-handling-commas-image-titles.html)

captainmerton 12-10-2011 10:27 AM

Handling Commas in image titles
 
Hi - looking for guidance on how best to handle commas. I have a website where people can updload images with related description text which appears on the website as the image ALT deta in the HTML. One problem i have is often people have images with filenames like New 'Cool' Bathroom.jpeg they then add a description with the same name. To be honest i'm not really interested in doing anything too complicated. Happy to probably just remove the commas so it doesnt cause the php to fall over as the comma is treated as part of the php code. Any thoughts?

Many thanks in advance.

sketchMedia 12-12-2011 11:19 PM

I'd just strip 'em off.

captainmerton 12-16-2011 07:52 PM

Thanks sketchMedia. Whats the best way to do this? preg_replace? Could you post me the code? Cheers.

wGEric 12-23-2011 12:48 AM

Something like this would strip everything off that isn't a letter, number, -, _, or .

PHP Code:

$file preg_replace('#[^a-Z0-9_-.]+#i'''$file); 

I didn't test it.

captainmerton 12-29-2011 05:00 PM

Thanks Eric. Just tried it and got the following failure:

Quote:

Warning: preg_replace() [function.preg-replace]: Compilation failed: range out of order in character class at offset 4
Any ideas why this might happen?

wGEric 01-05-2012 10:04 PM

Try removing the +

PHP Code:

$file preg_replace('#[^a-Z0-9_-.]#i'''$file); 



All times are GMT. The time now is 06:18 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0