PHP/String/Sub string — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 07:07, 26 мая 2010

Substring count

<?php
   $buzzwords = array("ex", "te", "xt");
$talk = <<< talk
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text  
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
talk;
   foreach($buzzwords as $bw) {
      echo "The word $bw appears ".substr_count($talk,$bw)." time(s).<br />";
   }
?>



Substring replace

<?php
   $ccnumber = "1234567899991111";
   echo substr_replace($ccnumber,"************",0,12);
?>



substr($string, 3)

<?
$alphabet_test = "abcdefghijklmnop";
print("3: " . substr($alphabet_test, 3));
?>



substr($String, 3, 5)

<?
$alphabet_test = "abcdefghijklmnop";
print("3, 5: " . substr($alphabet_test, 3, 5));
?>



substr($String, (2)

<?
$alphabet_test = "abcdefghijklmnop";
print("-3, 5: " . substr($alphabet_test, -3, 5));
?>



substr($String, -3, -5) (3)

<?
$alphabet_test = "abcdefghijklmnop";
print("-3, -5: " . substr($alphabet_test, -3, -5));
?>



substr($String, 3, -5) (4)

<?
$alphabet_test = "abcdefghijklmnop";
print("3, -5: " . substr($alphabet_test, 3, -5));
?>