Nasıl bir dize bir bölümünü Döşeme ve PHP kullanarak MySQL belirli bir dizesinde kaydetmek için?
Örnek:
Bir dize değeri varsa "REGISTER 11223344 here"
Nasıl dize "11223344"
kesebilir?
Özellikle "11223344" hedefleme ediyorsanız, o zaman kullanabilirsiniz str_replace
a>:
echo str_replace("11223344", "", "REGISTER 11223344 here");
Sen olarak tanımlanan, str_replace() kullanabilir:
str_replace($search, $replace, $subject)
Yani kod olarak yazabilirsiniz:
$subject = 'REGISTER 11223344 here';
$search = '11223344'
$trimmed = str_replace($search, '', $subject);
echo $trimmed
Düzenli ifadeler yoluyla daha iyi eşleştirme gerekiyorsa kullanabilirsiniz preg_replace().
Eğer kural tabanlı eşleştirme gerektiğinde, regex kullanmak gerekir
$string = "REGISTER 11223344 here";
preg_match("/(\d+)/", $string, $match);
$number = $match[1];
Bu sayı ilk seti maç, bu nedenle daha spesifik deneyin olması gerekiyorsa olacak:
$string = "REGISTER 11223344 here";
preg_match("/REGISTER (\d+) here/", $string, $match);
$number = $match[1];
substr() is a built-in php function which returns part of a string. The function substr() will take a string as input, the index form where you want the string to be trimmed. and an optional parameter is the length of the substring. You can see proper documentation and example code on http://php.net/manual/en/function.substr.php
NOT: Bir dize için indeks 0 ile başlar.