PHP/String/strstr — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:07, 26 мая 2010
Содержание
- 1 string strstr ( string haystack, string needle ) finds the first occurrence of a substring inside another string (parameter one)
- 2 strstr function demo
- 3 strstr() function returns the remainder of string beginning at the first occurrence.
- 4 strstr.php
- 5 strtr() function converts all characters contained in destination to their corresponding character matches in source.
- 6 strtr.php
string strstr ( string haystack, string needle ) finds the first occurrence of a substring inside another string (parameter one)
<?
$string = "http://www.example.ru/mypage.php";
$newstring = strstr($string, "www");
?>
strstr function demo
<?php
$haystack = "is a test";
$pos = strstr ($haystack, "is");
if (!$pos)
echo "String not found\n";
else
echo "String found: $pos\n";
?>
strstr() function returns the remainder of string beginning at the first occurrence.
Its syntax is: string strstr (string string, string occurrence)
<?
$url = "http://www.wbex.ru";
$domain = strstr($url, ".");
print $domain;
?>
strstr.php
<?php
$url = "sales@example.ru";
echo ltrim(strstr($url, "@"),"@");
?>
strtr() function converts all characters contained in destination to their corresponding character matches in source.
Its syntax: string strtr (string string, string source, string destination)
<?
$source = array("<title>" => "<h1>", "</title>" => "</h1>");
$string = "<h1>Today In PHP-Powered News</h1>";
print strtr($string, $source);
?>
strtr.php
<?php
$table = array("<b>" => "<strong>", "</b>" => "</strong>");
$html = "<b>Today</b>";
echo strtr($html, $table);
?>