PHP/String/Sub string

Материал из Web эксперт
Версия от 10:07, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Substring count

   <source lang="html4strict">

<?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).
"; }

?>

      </source>
   
  


Substring replace

   <source lang="html4strict">

<?php

  $ccnumber = "1234567899991111";
  echo substr_replace($ccnumber,"************",0,12);

?>


      </source>
   
  


substr($string, 3)

   <source lang="html4strict">

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

      </source>
   
  


substr($String, 3, 5)

   <source lang="html4strict">

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

      </source>
   
  


substr($String, (2)

   <source lang="html4strict">

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

      </source>
   
  


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

   <source lang="html4strict">

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

      </source>
   
  


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

   <source lang="html4strict">

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

      </source>