Good day all:

I've been experiencing a great difficulty resolving a problem concerning replacing

<br/>

to an actual newline inside a textarea box. Much of the problem has been because the data in the textarea is populated via a php script in this manner:

echo "formObj.servicedesc.value = '".toSafeString($inf["servicedesc"])."';\n";

Inside my textarea box I get the following:

<textarea><br/>On 12/01/10 @ 09:51<br/>We performed the following:<br/>
information update<br/><br/>----End of Service Report----<br/><br/>On 12/01/10 @ 09:43<br/>We performed the following:<br/>
information update<br/><br/>----End of Service Report----<br/><br/>On 11/29/10 @ 11:55<br/>We performed the following:<br/>
Information update<br/><br/>----End of Service Report----<br/><br/>On 11/29/10 @ 04:41<br/>We performed the following:<br/>
information update<br/><br/>----End of Service Report----<br/><br/>On 11/25/10 @ 09:34<br/>We performed the following:<br/>
Information updateds<br/><br/>----End of Service Report----<br/><br/>On 11/25/10 @ 08:56<br/>We performed the following:<br/>
We are performing an oil change<br/>Changing new brakes<br/>New tires<br/><br/>----End of Service Report----<br/>On 11/24/10 @ 09:43<br/>We performed the following:<br/>
3Click here to add details of todays service<br/><br/>----End of Service Report----<br/><br/>On 11/24/10 @ 09:15<br/>We performed the following:<br/>
<br/>On 11/22/10 @ 02:24<br/>We performed the following:<br/>
Click here to add details of todays serviced<br/><br/>----End of Service Report----<br/></textarea>";

Whereas, my ideal outcome is:

On 12/01/10 @ 09:51
We performed the following:

information update

----End of Service Report----

On 12/01/10 @ 09:43
We performed the following:

information update

----End of Service Report----

On 11/29/10 @ 11:55
We performed the following:

Information update

----End of Service Report----

My textarea box is written in html as follows:

<textarea name="servicedesc" id="servicedesc" cols=60 rows=12 disabled="true" style="position: absolute; right: 13; top: 260">

I have used numerous preg_replace functions but unable to resolve. I'm think I may be placing it incorrectly.

Any assistance with is greatly appreciated!
Mossa

echo "formObj.servicedesc.value = '".str_replace("\n", "<br/>", toSafeString($inf["servicedesc"]))."';\n";

Might do the trick

Thanks for the reply samarudge and for the suggestion. This addition cause the file to become unresponsive.

This is the complete php script that pulls the info from mysql and display data in an html page

<?php 
$connection = mysql_connect("localhost:xxxx","xxxxx","xxxxxx");   
mysql_select_db("shop",$connection); 

  function toSafeString($string) { 
   $string = preg_replace('/[\r\n]/s', '\\n', $string); 
   //$string = preg_replace('/<br \/>/', '\n', $string);//I have tried this with no success 
     return $string; 
   } 
    
if(isset($_GET['getClientId'])){  
  $clientId = preg_replace("/[^0-9|a-z|A-Z]/si", "", $_GET['getClientId']); 
  $res = mysql_query("select * from ajax_client where clientID='".$_GET['getClientId']."'") or die(mysql_error()); 
  //$res = mysql_query("UPDATE ajax_client SET drivenmileage=currentmileage-previousmileage");// this is the correct string for mileage substraction however it clashed with client lookup 
  if($inf = mysql_fetch_array($res)){ 
    echo "formObj.firstname.value = '".toSafeString($inf["firstname"])."';\n";     
    echo "formObj.lastname.value = '".toSafeString($inf["lastname"])."';\n";     
    echo "formObj.address.value = '".toSafeString($inf["address"])."';\n";     
    echo "formObj.zipcode.value = '".toSafeString($inf["zipcode"])."';\n";     
    echo "formObj.city.value = '".toSafeString($inf["city"])."';\n";     
    echo "formObj.state.value = '".toSafeString($inf["state"])."';\n"; 
    echo "formObj.dhtmlgoodies_category.value = '".toSafeString($inf["dhtmlgoodies_category"])."';\n"; 
    echo "formObj.dhtmlgoodies_subcategory.value = '".toSafeString($inf["dhtmlgoodies_subcategory"])."';\n"; 
    echo "formObj.caryear.value = '".toSafeString($inf["caryear"])."';\n"; 
    echo "formObj.servicedesc.value = '".toSafeString($inf["servicedesc"])."';\n";  
    echo "formObj.theDate.value = '".toSafeString($inf["theDate"])."';\n"; 
    echo "formObj.areacode.value = '".toSafeString($inf["areacode"])."';\n"; 
    echo "formObj.phoneprefix.value = '".toSafeString($inf["phoneprefix"])."';\n"; 
    echo "formObj.phonesufix.value = '".toSafeString($inf["phonesufix"])."';\n";  
    echo "formObj.email.value = '".toSafeString($inf["email"])."';\n";  
    echo "formObj.cellareacode.value = '".toSafeString($inf["cellareacode"])."';\n"; 
    echo "formObj.cellprefix.value = '".toSafeString($inf["cellprefix"])."';\n"; 
    echo "formObj.cellsufix.value = '".toSafeString($inf["cellsufix"])."';\n"; 
    echo "formObj.previousmileage.value = '".toSafeString($inf["previousmileage"])."';\n"; 
    //echo "formObj.currentmileage.value = '".toSafeString($inf["currentmileage"])."';\n"; 
    echo "formObj.servicearea.value = '".toSafeString($inf["servicearea"])."';\n"; 
    echo "formObj.commentonclient.value = '".toSafeString($inf["commentonclient"])."';\n"; 
    echo "formObj.drivenmileage.value = '".toSafeString($inf["drivenmileage"])."';\n";  

  } 
  else 
  { 
    echo "formObj.firstname.value = '';\n";     
    echo "formObj.lastname.value = '';\n";     
    echo "formObj.address.value = '';\n";     
    echo "formObj.zipcode.value = '';\n";     
    echo "formObj.city.value = '';\n";     
    echo "formObj.state.value = '';\n"; 
    echo "formObj.dhtmlgoodies_category.value = '';\n"; 
    echo "formObj.dhtmlgoodies_subcategory.value = '';\n"; 
    echo "formObj.caryear.value = '';\n"; 
    echo "formObj.servicedesc.value = '';\n"; 
    echo "formObj.theDate.value = '';\n"; 
    echo "formObj.areacode.value = '';\n"; 
    echo "formObj.phoneprefix.value = '';\n"; 
    echo "formObj.phonesufix.value = '';\n"; 
    echo "formObj.email.value = '';\n"; 
    echo "formObj.cellareacode.value = '';\n"; 
    echo "formObj.cellprefix.value = '';\n"; 
    echo "formObj.cellsufix.value = '';\n"; 
    echo "formObj.previousmileage.value = '';\n"; 
    //echo "formObj.currentmileage.value = '';\n"; 
    echo "formObj.servicearea.value = '';\n"; 
    echo "formObj.commentonclient.value = '';\n"; 
    echo "formObj.drivenmileage.value = '';\n"; 
      
        }     

} 

?>

Why not just do

function toSafeString($string) { 
   $string = preg_replace('/[\r\n]/s', '<br/>', $string); 
     return $string; 
   }

Instead of converting \r\n to \n then \n to <br/>?

This too, I have tried! In this case, the textarea box ignores and displays <br/>

Great news! Adding the following function to my php

function toSafeString($string) { 
   $string = str_replace('<br/>', "\n", $string); //this in particular
   $string = preg_replace('/[\r\n]/s', '\\n', $string); 
   return $string;  
}

the issue has been resolved! it was in particular the first $string.

To all of the great experts on this forum, I'm most appreciative for your selfless time.

The Best,
Mossa

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.