ramone_johnny Posted April 16, 2013 Share Posted April 16, 2013 Hey guys, Can someone tell me what the equivalent of this is in PHP? <%response.write replace(property_description, vbCrlf,"<br>")%> Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/ Share on other sites More sharing options...
DavidAM Posted April 16, 2013 Share Posted April 16, 2013 vbCrlf is a Carriage-Return--Line-Feed pair. In PHP, it is "\r\n". Or you could add a define in the PHP code: define('vbCrlf', "\r\n"); Note: The double-quotes are required here because those escape sequences are not interpreted in single-quotes. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425100 Share on other sites More sharing options...
ramone_johnny Posted April 16, 2013 Author Share Posted April 16, 2013 Thank you. Errr....bit more help? <? echo define($property_description, 'vbCrlf', "\r\n"); ?> No? Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425102 Share on other sites More sharing options...
shlumph Posted April 16, 2013 Share Posted April 16, 2013 This would be something like: echo str_replace("\r\n", "<br>", $property_description); Or echo str_replace("<br>", "\r\n", $property_description); Depending on the definition of the replace function in ASP. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425103 Share on other sites More sharing options...
ramone_johnny Posted April 16, 2013 Author Share Posted April 16, 2013 Thank you. It seems I still have this annoying issue. My text is being displayed like this........ I have a room available in my 2 bed flat in Ashgrove. The flat is ina quiet block of six units and is an older style flat so nice androomy.The room is unfurnished, but I can source a bed if you need.There is great storage in the room with built in cupboards, and theroom is large enough to fit a queen bed, chest of draws andbedside table. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425107 Share on other sites More sharing options...
DavidAM Posted April 16, 2013 Share Posted April 16, 2013 Sorry, I gave an incomplete answer. shlumph is correct, depending on which way that asp statement is. If you are replacing CRLF with <BR> (for HTML display) it would be the first one. echo str_replace("\r\n", "<BR>", $property_description); Or you can look at the nl2br function, which doesn't actually replace them, it just inserts the HTML <BR> before the CRLF (which is fine for HTML). echo nl2br($property_description); What I was getting at with the define, was something like this define('vbCrlf', "\r\n"); echo str_replace(vbCrlf, '<BR>', $property_description); Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425109 Share on other sites More sharing options...
ramone_johnny Posted April 16, 2013 Author Share Posted April 16, 2013 Thanks again. That makes sense. (Sorry my background is ASP) I tried the nl2br method and got the same result. You can see the issue I'm faced with here (this is the asp version) in the description. http://www.housemates.com.au/share_ads/share_open.asp?share_ID=7243 It's really annoying. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425111 Share on other sites More sharing options...
ramone_johnny Posted April 16, 2013 Author Share Posted April 16, 2013 Strangely enough the problem goes away when I make the table wider. Urrgh... Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425119 Share on other sites More sharing options...
shlumph Posted April 16, 2013 Share Posted April 16, 2013 Sounds like it was word-wrapping. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425151 Share on other sites More sharing options...
Psycho Posted April 16, 2013 Share Posted April 16, 2013 What, exactly, are you trying to accomplish? It seems you are replacing linebreaks in the source and converting them to <br> tags - which causes a line break in the HTML content. But, it seems that is creating some undesired output. Looking at this sample output: I have a room available in my 2 bed flat in Ashgrove. The flat is in a quiet block of six units and is an older style flat so nice and roomy. The room is unfurnished, but I can source a bed if you need. There is great storage in the room with built in cupboards, and the room is large enough to fit a queen bed, chest of draws and bedside table. It seems that the source content has linebreaks that you don't want included in the output. We really need to see a sample of the actual source content and how you want it to be displayed to provide a good answer. Based on the above, I *think* the answer might to convert double linebreaks in the source to an HTML <BR> tag and leave the rest alone. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425168 Share on other sites More sharing options...
ramone_johnny Posted April 17, 2013 Author Share Posted April 17, 2013 Aha! I managed to get it sorted out. (using brute force) Thanks to the suggestion made above by psycho. <? echo str_replace("\r\n\r\n", "<div style=font-size:0;height:10px;></div>", $property_description); ?> Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425302 Share on other sites More sharing options...
trq Posted April 17, 2013 Share Posted April 17, 2013 That makes both little sense and invalid html. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425306 Share on other sites More sharing options...
Psycho Posted April 17, 2013 Share Posted April 17, 2013 Yeah, why not just replace the double linebreaks in the source with a <br> tag (or two if needed) Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425472 Share on other sites More sharing options...
shlumph Posted April 18, 2013 Share Posted April 18, 2013 I'm guessing because, last time I checked, double <br>'s don't have a standard height across browsers. This can be modified with CSS... but I think that's why he did it that way. The style attribute should be quoted. Better yet, give it a class name like "break", then move the styling into a stylesheet. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425591 Share on other sites More sharing options...
Psycho Posted April 18, 2013 Share Posted April 18, 2013 I'm guessing because, last time I checked, double <br>'s don't have a standard height across browsers. This can be modified with CSS... but I think that's why he did it that way. Then the content should be put in a paragraph tag, <P>, and it should be styled with appropriate line height properties. Then the <BR> tag will generate the appropriate height. Using an empty <DIV> tag is very poor form. In fact, that could cause very different display on different browsers. Link to comment https://forums.phpfreaks.com/topic/277014-convert-asp-to-php-replace-vbcrlf/#findComment-1425642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.