Böyle bir şey yapabileceğini:
Örnek 1: Trim boşlukların
<?php
# Test variable
$string = "HELLO I HAVE WHITE SPACEEE!!1";
# Count all whitespaces
# Contains more than 1 whitespace
if(substr_count($string, ' ') > 1) {
# Example 2: Remove the whitespaces
$string = trim($string);
}
# Ouput: HELLO I HAVE WHITE SPACEEE!!1
echo $string;
?>
Örnek 3: more than 1
<?php
# Test variable
$string = "HELLO I HAVE WHITE SPACEEE!!1";
# Count all whitespaces
# Contains more than 1 whitespace
if(substr_count($string, ' ') > 1) {
# Example 1: Remove the whitespaces
$string = preg_replace('/\s+/', '', $string);
}
# Ouput: HELLOIHAVEWHITESPACEEE!!1
echo $string;
?>
Örnek 2 eğer boşlukları Kaldır değiştirin whitespaces
<?php
# Test variable
$string = "HELLO I HAVE WHITE SPACEEE!!1";
# Count all whitespaces
# Contains more than 1 whitespace
if(substr_count($string, ' ') > 1) {
# Example 1: Replace the whitespaces
$string = preg_replace('/\s+/', ' ', $string);
}
# Ouput: HELLO I HAVE WHITE SPACEEE!!1
echo $string;
?>
Örnek 4:
<?php
# Test variable
$string = "HELLO I HAVE WHITE SPACEEE!!1 And I like bananas.";
# Count all whitespaces
# Contains more than 1 whitespace
if(substr_count($string, ' ') > 1) {
# Example 1: Replace the whitespaces
$string = preg_replace('/\s\s+/', '', $string);
}
# Ouput: HELLOIHAVEWHITESPACEEE!!1 And I like bananas.
echo $string;
?>
'trim (string) işlevini kullanın;' işlev –
Yani, trim() işlevi gibi mi? –
Gibi ** Matt Magallo ** içerikte bir değişken kullanılıyorsa, 'trim(); ' –