Jump to content


Photo

Help w/ Regular Expressions


  • Please log in to reply
3 replies to this topic

#1 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 19 September 2006 - 10:27 PM

Ok so i'm lost atm with regular expressions.
Here's the scenario. Users submit text through a textbox, stores it in sql, then i display it on a page. I want them to be able to use HTML (to show images, bold, etc) but i dont want the images to go over a certain size.. So if someone posts a huge image, i want to resize it within the img src tag. so if they put in
<img src="blah.jpg">
and its over X amount in width then it remakes it to
<img src="blah.jpg" width="20">
. Hopefuly made myself clear, gotta love being sick.
Thanks.

#2 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 19 September 2006 - 10:28 PM

I don't see how regular expressions are going to help you solve that problem.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#3 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 19 September 2006 - 10:32 PM

or anything else then? I thought reg expressions would since you can strip tags, etc with them?

#4 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 19 September 2006 - 11:06 PM

There are several considerations when providing posting capabilities to a website.  You want to give users the ability to format their posts using basic HTML, but you want to prevent them from embedding harmful scripts.

The best solution in my opinion is to use a combination of htmlentities and regular expressions.  You allow your users to enter special codes in square brackets in their posts which can be saved as is into the database.  Then when the data is displayed you use regexps to pull out the codes and replace them with HTML equivalents, such as exchanging for [b]<b>.  This way your forums will only display user-entered "html" that you've allowed and coded for.

If you want to display images in your forums, determining if the image is too large to display within your page width and needs to be resized is another issue entirely.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users