Skip to main content
January 27, 2014
Question

break line <br>

  • January 27, 2014
  • 1 reply
  • 500 views

<cfset mystring ="Jonh, Doe">

<cfset TheText = replace(mystring, ',', '<br>' , "ALL")>

<cfdump var="#TheText#">

why the results shows Jonh<br>Doe instead of

John

Do

Can anyone pls help?

Thanks

    This topic has been closed for replies.

    1 reply

    Inspiring
    January 27, 2014

    Because you're dumping the object rather than outputting it.

    Try <cfoutput>#TheText#</cfoutput>

    Here's the technical.

    Even though 'John<br>Doe' looks like HTML to you, it is nothing more than a string to ColdFusion.  Text has a mime type of 'text/plain', which the browser iterprets as the actual value itself (John<br>Doe).  So ColdFusion is showing you the actual value of that variable.  Nothing has been output to the buffer for processing.  In order for ColdFusion to output the value of the variable to the buffer so that the browser can attempt to interpret it, you'll need <cfoutput>

    Also, this is not a healthy way of writing code (mixing text and HTML).  Browsers do a VERY forgiving job of interpreting what you output as best as they can, but if you're going to output HTML, then wrap the output in the appropriate paragraph tag, ie:

    <cfset example = '<p>John<br>Doe</p>' />

    <cfoutput>#example#</cfoutput>