|
 |
|
เรื่องหาช่องว่า แล้วตัดคำครับ คือผม ปัจจุบัน ผมเก็บข้อมูล ชื่อ เป็นแบบนี้ครับ | สมชาย เจริญดี | อยู่ใน ฟิลด์เดียวกันครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
<?
//------------ การแยกคำ -----------
//------------ By P@e ----------
$x = "สมชาย เจริญดี";
list($t1, $t2) = split(' ', $x);
echo $x."<br>";
echo "-------------------------------"."<br>";
echo $t1, '<br>', $t2; //เอา 2 ค่านี้ไป Insert
?>
?>
|
 |
 |
 |
 |
Date :
2009-07-02 12:48:16 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่รู้เหมือนกันหรือเปล่า
Code (PHP)
<?php
$text = "สมชาย เจริญดี";
$a = expolde(" ",$text);
$t1 = $a[0];
$t2 = $a[1];
echo " | ".$t1." | ". $t2. " | ";
?>
|
 |
 |
 |
 |
Date :
2009-07-02 13:05:11 |
By :
sirikulo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ได้ทั้ง 2 เลยครับ แต่ อันที่ 2 ต้องแก้ นิดหน่อย ตรงนี้ครับ expolde เป็น explode พิมพ์ผิดเฉยๆ ครับ ขอขอบคุณมากเลย ครับ ผม + ไห้ ท่านทั้ง 2 เป็น แทนคำขอบคุณอีกครั้งครับ
|
 |
 |
 |
 |
Date :
2009-07-02 13:41:20 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอเพิ่มนะครับ ถ้า มัน เว้นช่องว่าเดียว กันก็ปกติ แต่ มีที่ เว้น 2 ช่อง จะทำไงดีครับ เพราะ นามสกุล มันจะหาย ไป
|
 |
 |
 |
 |
Date :
2009-07-02 14:06:15 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แหะ ๆ พิมพ์ผิดเฉยเลย สงสัยรีบพิมพ์ไปหน่อย
|
 |
 |
 |
 |
Date :
2009-07-02 14:06:41 |
By :
sirikulo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอถามเพิ่มนะครับ
ถ้า มัน เว้นช่องว่างเดียว หรือ 2 ช่อง หรือ 3 ช่อง จะทำไงดีครับ เพราะ นามสกุล มันจะหาย ไป
คือว่าง บางคน ก็ 1 ชอง บาง คน 2 บางคน 3 ประมาณีนี้อะครับ
|
 |
 |
 |
 |
Date :
2009-07-02 14:22:36 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนขึ้นมาเล่น ๆ เอาไปแปรสภาพเอาเองก็แล้วกันนะ
Code (PHP)
<?php
<?php
$t1="";
$t2="";
$t3="";
$t4="";
$text = "สมชาย เจริญดี";
$Fname="";
$Sname="";
$a = explode(" ",$text); // หนึ่ง เคาะ
$b = explode(" ",$text); // สอง เคาะ
$c = explode(" ",$text);// สามเคาะ
$t1 = $a[0];
$t2 = $a[1];
if(empty($t2))
{
$t3 = $b[1];
}
if(empty($t3))
{
$t4 = $c[1];
}
if(empty($t2))
{
$Sname=$t3;
}
else
{
$Sname=$t2;
}
echo " | ".$t1." | ". $t2. " | ".$t3." | ".$t4;
echo "<br>";
echo "t1: ".$t1."<br>";
echo "t2: ".$t2."<br>";
echo "t3: ".$t3."<br>";
echo "t4: ".$t4."<br>";
echo "Fname : ".$t1."<br>";
echo "Sname: ".$Sname."<br>";
?>
?>
|
 |
 |
 |
 |
Date :
2009-07-02 14:28:57 |
By :
sirikulo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณมากครับ
ผมดัดแปลงนิดหน่อยนะครับ ไม่ว่ากันนะ เพราะ copy มาแล้วค่อยแปลง
Code (PHP)
<?php
$text = trim($name);
$a = explode(" ",$text); // หนึ่ง เคาะ
$b = explode(" ",$text); // สอง เคาะ
$c = explode(" ",$text);// สามเคาะ
$t1 = $a[0];
$t2 = $a[1];
if(empty($t2))
{ $t2 = $b[1];
if(empty($t2)){ $t2 = $c[1];}}
?>
|
 |
 |
 |
 |
Date :
2009-07-02 15:02:47 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ 
|
 |
 |
 |
 |
Date :
2009-07-02 15:53:28 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|