han2754 Posted September 22, 2008 Share Posted September 22, 2008 hi all I just try to run the code below ( I used wamp) the php version is 5.2.6 I think there something wrong with my configuration setting,but i am not sure I hope help to find it thank you -------------------------------- <?php $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); echo $new; // <a href='test'>Test</a> ?> -------------------------------- the result displayed on screen is below -------------------------------- <a href='test'>Test</a> -------------------------------- Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/ Share on other sites More sharing options...
Mchl Posted September 22, 2008 Share Posted September 22, 2008 And what would you expect the result to be? Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647527 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 if you view the source of the webpage you'll see it is <a href='test'>Test</a> as is what htmlspecialchars() does. Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647532 Share on other sites More sharing options...
waynew Posted September 22, 2008 Share Posted September 22, 2008 Yes. View the source. Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647572 Share on other sites More sharing options...
han2754 Posted September 22, 2008 Author Share Posted September 22, 2008 And what would you expect the result to be? here is may be more clearer example the code is below ------------------------- <?php # testslashn php # print "Creating a table...\n"; print "Inserting some rows to the table...\n"; print "Query some rows from the table...\n"; ?> --------------------------- I hope the 3 sentences print in three lines,but it print in only one line . Yes I can replace \n with <br> ,but why the book tell me that I can line feed by using \n ,if it doesn't really work ? thanks hanafi tan Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647647 Share on other sites More sharing options...
Mchl Posted September 22, 2008 Share Posted September 22, 2008 It works. Thing is, you watch the output from php script that is parsed by web browser. And for web browsers /n means nothing. If you check source of what is displayed, you will see that you have this in three lines. If you save the page to the text file and open it in the notepad, you'll see three lines. Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647660 Share on other sites More sharing options...
genericnumber1 Posted September 22, 2008 Share Posted September 22, 2008 htmlspecialchars() isn't to preformat line breaks for a browser (read Mchl's explanation, it's a good one), use nl2br(). Link to comment https://forums.phpfreaks.com/topic/125264-special-html-char-doest-work/#findComment-647720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.