เมนูหลัก

Regular expression

เริ่มโดย awat, 21 พฤษภาคม 2008, 11:05:18

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

awat

คือผม ต้องการที่จะค้าหาและแทนค่า

<?php
  $content 
'Some men keep trying and never get anywhere with dating';
  
$content ereg_replace('[color=red]x[/color]','',$content); //ต้องการตัด Some men keep ออก
  
$content ereg_replace('[color=blue]y[/color]','',$content);  //ต้องการตัด with dating ออก
  
echo $content;  // ได้ผลลัพท์เป็น  trying and never get anywhere
?>



x = อะไรครับ
ัy = อะไรครับ

ขอบคุณครับ งงกับ regular expression
.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal

awat

ไม่เห็นมีคนตอบเลย :-X
.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal

WindowsX

ใช้ str_replace เถอะครับถ้าจะแทนคำโดยทั่วไป

str_replace("a","b",$str) จะแทนคำว่า a ด้วย b ใน var str ครับ

guy852

แบบนี้ครับ

<?php
$c 
"EThaiZone is Man";
$c str_replace("Thai","Yaoi",$c);
$c str_replace("Man","Gay",$c);

echo 
$c;
?<>

awat


<?php
  $content 
'Some men keep trying and never get anywhere with dating';
  
$content ereg_replace('[color=red]x[/color]','',$content); //ต้องการตัด ก่อนหน้า and ออก
  // ถึงบรรทัดนี้ $content = 'and never get anywhere with dating';
  
$content ereg_replace('[color=blue]y[/color]','',$content);  //ต้องการตัด หลัง get  ออก
  // ถึงบรรทัดนี้ $content = 'and never get';
  
echo $content;  // ได้ผลลัพท์เป็น  and never get
?>



อย่างนี้ครับ
.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal

zimba

อ้างถึงจาก: guy852 ใน 21 พฤษภาคม 2008, 12:02:28
แบบนี้ครับ

<?php
$c 
"EThaiZone is Man";
$c str_replace("Thai","Yaoi",$c);
$c str_replace("Man","Gay",$c);

echo 
$c;
?<>


;D ;D ;D

น้องโจ้โดนอีกแล้ว.....

awat

อันกระทู้ให้มีคนช่วย  :-X :-X
.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal

EThaiZone

เกือบจะไม่ตอบแล้วเชียว  :(

<?php
  $content 
'Some men keep trying and never get anywhere with dating';
  
$content ereg_replace('(.*)and','and',$content); //ต้องการตัด ก่อนหน้า and ออก
  // ถึงบรรทัดนี้ $content = 'and never get anywhere with dating';
  
$content ereg_replace('get(.*)','get',$content);  //ต้องการตัด หลัง get  ออก
  // ถึงบรรทัดนี้ $content = 'and never get';
  
echo $content;  // ได้ผลลัพท์เป็น  and never get
?>


ลวกๆ หน่อย  :P

เกรียนเทพ

อ้างถึงจาก: guy852 ใน 21 พฤษภาคม 2008, 12:02:28
แบบนี้ครับ

<?php
$c 
"EThaiZone is Man";
$c str_replace("Thai","Yaoi",$c);
$c str_replace("Man","Gay",$c);

echo 
$c;
?<>


;D ;D ;D ;D ;D