Jump to content

Help w/ Regular Expressions


scottrohe

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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.