|
 |
|
ถามเรื่องการแทนที่หรือแทรกข้อความครับ จริงๆแล้ว ผมต้องการใช้ split เพื่อตัดออกมาเป็น array เลย แต่ก็ตัดจากช่องว่างไม่ได้ |
|
 |
|
|
 |
 |
|
จริงๆแล้ว ผมต้องการใช้ split เพื่อตัดออกมาเป็น array เลย แต่ก็ตัดจากช่องว่างไม่ได้
แล้วผมก็ลองแทรก / เข้าไปแทนที่ช่องว่าง โดยใช้ str_replace() แต่ทำไมมันไม่แทรกให้ ผมไม่เข้าใจอ่ะครับ
ขอคำแนะนำหน่อยนะครับ ขอบพระคุณครับ
Code (PHP)
sms.php
<script type="text/javascript">
function textMobile1(field1,nummobile)
{
var Arrx = field1.value;
var arrMobile ;
var i = 0;
var count = 0;
var arr;
Arrx = Arrx.replace(/\r\n/g,"\n");
if(Arrx.length == 0)
{
nummobile.value='0';
}
else
{
arrMobile = Arrx.split ('\n');
while (i<arrMobile.length)
{
arr = arrMobile[i];
arr = arr.replace("-","");
if((arr.substring(0,3)== "668" && arr.length == 11) &&((!isNaN(Number(arr))) && (arr.indexOf(".")<0)))
{
count=count+1;
}
else
{
if((arr.substring(0,2) == "08") && (arr.length == 10)&&((!isNaN(Number(arr))) && (arr.indexOf(".")<0)))
{
count = count+1;
}
}
i = i + 1;
}
nummobile.value = parseInt(count);
}
}
</script>
<body>
<form action="sender.php" enctype="multipart/form-data" method="POST" name="myForm">
Mobile Number : <br/>
<textarea name="mobile" wrap="soft" cols="35" rows="8"
OnKeyDown="textMobile1(document.myForm.mobile,document.myForm.numobile);"
OnKeyUp="textMobile1(document.myForm.mobile,document.myForm.numobile);"
Onkeypress="textMobile1(document.myForm.mobile,document.myForm.numobile);">
</textarea>
<br/>
Mobile Count <input readonly type="text" name="numobile" size="5" maxlength="5" value=0> จำนวนเบอร์โทรศัพท์
<br/>
<input type="submit" Value="Submit" name="cmdSubmit" id="cmdSubmit" />
</form>
</body>


Code (PHP)
sender.php
<?php
$mobile = $_POST["mobile"];
echo str_replace(" ", "/", $mobile) ;
?>
Tag : PHP, JavaScript

|
ประวัติการแก้ไข 2011-12-08 09:33:43 2011-12-08 09:34:14
|
 |
 |
 |
 |
Date :
2011-12-08 09:32:32 |
By :
pinmanfa |
View :
1364 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เคยใช้ preg_replace แทนที่ช่องว่างค่ะ ไม่รู้ว่าพอช่วยได้ไหม ^^
Code (PHP)
echo preg_replace('/\s+/', '/', $mobile);
|
 |
 |
 |
 |
Date :
2011-12-08 09:55:11 |
By :
kukkuk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<div id="example1_count" style="display:none"></div>
<textarea id="example1" rows="5" cols="50" class="telephone_count"></textarea>
<div id="example2_count" style="display:none"></div>
<input id="example2" type="text" size="50" class="telephone_count" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.telephone_count').each(function() {
var input = '#' + this.id;
var count = input + '_count';
$(count).show();
telephone_count(input, count);
$(this).keyup(function() { telephone_count(input, count) });
});
});
function telephone_count(field, count) {
var number = 0;
var matches = $(field).val().match(/\b/g);
if(matches) {
number = matches.length/2;
}
$(count).text( 'เบอร์โทรศัพท์ ' + number + ' \nเบอร์' );
}
</script>
|
 |
 |
 |
 |
Date :
2011-12-08 10:00:00 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เมื่อวานเข้าเว็บไม่ได้ ไม่รู้ว่าล่มหรือยังไง เห็นติดต่อฐานข้อมูลไม่ได้
ก็เลยหาวิธีแก้ไปเองได้แบบนี้อ่ะครับ
Code (PHP)
str_replace(substr($mobile,10,2),"/",$mobile);
ขอบคุณนะครับสำหรับคำตอบ ผมจะลองนำไปใช้นะครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2011-12-09 09:36:36 |
By :
pinmanfa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|