Re: str_replace(), and correctly positioned HTML tags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 12:26 PM +0900 5/26/06, Dave M G wrote:
Tedd, Adam,

Thank you for your advice. While I'm very grateful for your advice, unfortunately, it seems that the core of what you suggest do not fit my situation.

First, with Adam's suggestion that I use <br /> instead of <p>. The output I am generating is akin to what csszengarden.com generates, so that I can have complete CSS control over page layout and style. <br /> tags are limited in their scope of design control as compared to <p> tags, so they are insufficient.

Second, with Tedd's advice that I place the variable without formatting within the HTML code. I apologize if I was unclear, as I seem to have given you the wrong impression. I am absolutely trying to separate content from design, which is why everything the user stores is in plain text, and all the formatting happens when it is displayed. None of the modifications which add HTML to the variable get put back into the database.

The only small formatting consideration that does get stored in the database are the simulated tags (eg: --++ for <h3>). I'm not totally thrilled about letting users create some formatting with simulated tags, but the trade off is for giving the users more flexibility. I'm following the same model as WikiMedia, SMF Forums, and other PHP based user input interfaces. And I am trying to be more strict and less expansive than they are.

I really am grateful for your advice, but it seems that I really do need to find a way to create <p> tags around the text when it is displayed.

But I definitely thank you for giving me something to think about, and also the tips on how to make my code more efficient.

It's my hope that someone can still steer me towards the ability to get <p> tags surrounding paragraphs, and to be able to separate <h3> and other tags from within those <p> tags.

--
Dave M G


Dave:

If you want to go that way, then I suggest that you place a "preview" page for the poster. Most people don't want to post something that's all screwed up and will take the time to fix it IF they are given the chance.

That way, the only real problem you have to deal with is what happens when someone enters something that isn't correct.

I might also suggest that there are functions that will help you sort out acceptable html from unacceptable html.

For example, strip_tags($text, '<p>'); will allow both <p> and </p> tags, but will prohibit everything else.

If you want a more complete answer to your problem, you can use regular expressions to extract and manipulate tags, but it's complex.

A good read, and what appears to be a solution, can be found on pages 153-159 of PHP String Handling Handbook by Matt Wade et al published by Wrok (ISBN 1-86100-835-X) in 2003.

I've looked for the download support files they claim to have, but found none.

http://support.apress.com/books.asp?bID=186100835x&s=0&Go=Select+Book

I've contacted one of the authors, let's see if he provides the code. If he does, I'll send it to you.

hth's.

tedd

--
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux