0
我有處理文本像這樣的形式:\\ [R \\ň\\ [R \\ň文本之後出現的字符插入形式PHP
$group_description = mysql_real_escape_string(trim($_POST['group_description']));
$insert_group_sql = 'INSERT INTO table_name(group_description)
VALUES ("'.$group_description.'" ') ';
和輸出分貝結果這樣的另一頁:
$group_description = $row['group_description'];
//Convert all urls to links
$group_description = preg_replace('#([\s|^])(www)#i', '$1http://$2', $group_description);
$pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
$replacement = '<a href="$1" target="_blank">$1</a>';
$group_description = preg_replace($pattern, $replacement, $group_description);
$group_description = str_replace(array('\r\n', '\n\r'), '<br />',$group_description);
/* Convert all E-mail matches to appropriate HTML links */
$pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
$pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
$replacement = '<a href="mailto:\\1">\\1</a>';
$group_description = preg_replace($pattern, $replacement, $group_description);
我最終什麼樣的主意是這樣的頁面:http://www.comehike.com/hikes/hiking_group.php?hiking_group_id=54
而且我也不太清楚這個使用者如何得到\\ \\ [R n個字符去那裏:)
任何想法出錯的地方?如果這很重要,我使用MySQL數據庫。謝謝!
用戶可能會用換行符粘貼文本。嘗試在'str_replace(array('\ r \ n','\ n \ r')...'中使用雙引號。 – bfavaretto
@bfavaretto在輸入文本之前應該這樣做嗎?或者當我準備好顯示它時? – Genadinik
如何/爲什麼用戶在新行之前輸入3個反斜槓?因爲它在那裏?用戶真的沒有這個意義。 – Genadinik