PHP/String/strstr
Содержание
- 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 ", "</title>" => "
- 7 Today In PHP-Powered News
string strstr ( string haystack, string needle ) finds the first occurrence of a substring inside another string (parameter one)
<source lang="html4strict">
<?
$string = "http://www.example.ru/mypage.php"; $newstring = strstr($string, "www");
?>
</source>
strstr function demo
<source lang="html4strict">
<?php
$haystack = "is a test"; $pos = strstr ($haystack, "is"); if (!$pos) echo "String not found\n"; else echo "String found: $pos\n";
?>
</source>
strstr() function returns the remainder of string beginning at the first occurrence.
<source lang="html4strict">
Its syntax is: string strstr (string string, string occurrence) <? $url = "http://www.wbex.ru"; $domain = strstr($url, "."); print $domain; ?>
</source>
strstr.php
<source lang="html4strict">
<?php
$url = "sales@example.ru"; echo ltrim(strstr($url, "@"),"@");
?>
</source>
strtr() function converts all characters contained in destination to their corresponding character matches in source.
<source lang="html4strict">
Its syntax: string strtr (string string, string source, string destination) <?
$source = array("<title>" => "", "</title>" => "
"); $string = "Today In PHP-Powered News
";print strtr($string, $source);
?>
</source>
strtr.php
<source lang="html4strict">
<?php
$table = array("" => "", "</b>" => ""); $html = "<b>Today"; echo strtr($html, $table);
?>
</source>