Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

str_replace(chr(13),"\\n",$text);

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
ronsen
Smarty Rookie


Joined: 07 Jun 2003
Posts: 13
Location: Baden/Wien Austria

PostPosted: Tue Jun 24, 2003 9:58 am    Post subject: str_replace(chr(13),"\\n",$text); Reply with quote

Hi Forum,
I try to find a solution for my problem for a coupler hours. I dig in the forum and in manuals but can't find a help, so I hope one of you can give me a hand.
In a mysql-table I got a field, type text
íf I edit the text via a form in a
<textarea> </textarea> and after this,
before I save the text I try to replace chr(13) like that
Code:

$num=substr_count($text,chr(13));
echo "num=";
echo $num;    //is 95
if ($num>0) {
   $text= str_replace(chr(13),"\\n",$text);
  }
echo "<p>after<p>"; 
$num=substr_count($text,"\n");
echo "'\\n='";
echo $num;  //is 95

when I fetch the text from table like:

Code:

$res = mysql_query($sql);
$results = array();
$i=0;
while ($r=mysql_fetch_array($res)) {
            $tmp = array(

                "news_titel"          => $r["titel"],
                "news_text"           => $r["text"]

            );
            $results[$i++] = $tmp;
}
// pass the results to the template


$num=substr_count($results,chr(13));
echo "crNum=";
echo $num;   // is 0
$num=substr_count($results,"\n");
echo "<p>Num2n=";
echo $num;  // is 0

die();



why can't I save the cr to the mysql-table?
I also tried

Code:

//only one backslash
$text= str_replace(chr(13),"\n",$text);
// use html tag
$text= str_replace(chr(13),"<br>",$text);
// got from this forum
$results=preg_replace('/\<br\s*\/?\>/i', "\n", $results);
//pray 10min for wisdom

TIA
Ron



?>[/php]
Back to top
View user's profile Send private message
ronsen
Smarty Rookie


Joined: 07 Jun 2003
Posts: 13
Location: Baden/Wien Austria

PostPosted: Tue Jun 24, 2003 7:57 pm    Post subject: Reply with quote

I'm sorry I got it what a shame
nl2br
Ron
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP