TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-10-2011, 10:27 AM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default 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.
captainmerton is offline  
Reply With Quote
Old 12-12-2011, 11:19 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

I'd just strip 'em off.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-16-2011, 07:52 PM   #3 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Thanks sketchMedia. Whats the best way to do this? preg_replace? Could you post me the code? Cheers.
captainmerton is offline  
Reply With Quote
Old 12-23-2011, 12:48 AM   #4 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

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.
__________________
Eric
wGEric is offline  
Reply With Quote
Old 12-29-2011, 05:00 PM   #5 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

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?
captainmerton is offline  
Reply With Quote
Old 01-05-2012, 10:04 PM   #6 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Try removing the +

PHP Code:
$file preg_replace('#[^a-Z0-9_-.]#i'''$file); 
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Image Reflections in PHP Rendair Advanced PHP Programming 17 11-30-2011 08:41 AM
image upload script with watermark hitchy Absolute Beginners 0 08-12-2011 08:58 AM
Image Upload Speed captainmerton General 6 03-29-2011 08:33 AM
The Big GD Guide - Part 2 Rendair Advanced PHP Programming 3 03-07-2008 12:14 AM


All times are GMT. The time now is 01:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design