การใช้ str_replace( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
<?php
// Order of replacement
$str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; // ข้อความ
$order = array("\r\n", "\n", "\r"); //ตัวข้อความที่ใช้ค้นหา
$replace = '<br />'; // ข้อมูลที่จะเอาไปแทนที่
// Processes \r\n's first so they aren't converted twice.
$newstr = str_replace($order, $replace, $str);
?>$text = "asd'$%#&12"; $txt = str_replace(array( "'" , '$' , '%', '#', '&' ), '_', $text); echo '<br>'. $txt;
$order = array(“\r\n”, “\n”, “\r”); //ตัวข้อความที่ใช้ค้นหา
และ
$txt = str_replace(array( “‘” , ‘$’ , ‘%’, ‘#’, ‘&’ ), ‘_’, $text);
จะเขียนให้ครอบคลุมอักษรพิเศษทุกตัวได้อย่างไร
$data = preg_replace("/[^a-z\d]/i", '_', $data);
echo $data;