scottrohe Posted September 19, 2006 Share Posted September 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 19, 2006 Share Posted September 19, 2006 I don't see how regular expressions are going to help you solve that problem. Quote Link to comment Share on other sites More sharing options...
scottrohe Posted September 19, 2006 Author Share Posted September 19, 2006 or anything else then? I thought reg expressions would since you can strip tags, etc with them? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 19, 2006 Share Posted September 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.