Jump to content

Archived

This topic is now archived and is closed to further replies.

scottrohe

Help w/ Regular Expressions

Recommended Posts

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 [code]<img src="blah.jpg">[/code] and its over X amount in width then it remakes it to [code]<img src="blah.jpg" width="20">[/code]. Hopefuly made myself clear, gotta love being sick.
Thanks.

Share this post


Link to post
Share on other sites
I don't see how regular expressions are going to help you solve that problem.

Share this post


Link to post
Share on other sites
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 [b]as is[/b] 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 [b][b][/b] for [b]<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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.