Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts

    How to add semantics to output strings

    Firstly, I would like to iterate that I'm very much new to php so I don't know many of the functions etc. I have built a little CMS for my site that allows members to post blogs and add them to the database. Then they are listed and the clients can view them if they click the right link... general stuff.

    I'm curious about how the actual 'code' behind the blogs is output. I'm currently using nl2br to keep the line spaces in, but because everything else in the site is supposed to be semantic and 'properly' coded, I would like to apply this to the articles to. So, for example, rather than having two line breaks after each paragraph I would like the paragraphs to be wrapped in <p> tags so they look as my paragraphs should and I'm not having to use any horrible <br /> tags.

    Is this possible, and if so how? And would it be done when the blog is added to the database, or upon return.

    Also, on a side note, could someone quickly explain to me what exactly mysql_real_escape_string actually does, or what text it affects? Could I use it for this type of database input?

    Thanks guys
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    well if it really bothers you that much PHP has loads of string manipulation functions, you could for example ...
    PHP Code:
    <?
    $input
    ='<p>'.str_replace('<br /><br />','</p><p>',$input).'</p>';
    ?>
    Ideally you would leave the data in the database intact (in case you change your mind about formatting later), though re-parsing the same content every time you show it has performance implications, so thats a trade-off.

    mysql_escape_real_string actually uses the mysql database to do the escaping, internally it calls a mysql function, unlike mysql_escape_string which simply fakes it at a php level.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    That was what I was originally going to look into doing and that would work really well for simple content... the only trouble is that sometimes headings are put into these blogs, which makes things a little more interesting :s
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •