1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$string = 'The lazy fox jumped over the fence';
2
3if (str_contains($string, 'lazy')) {
4 echo "The string 'lazy' was found in the string\n";
5}
6
7
1
2<?php
3$mystring = 'abc';
4$findme = 'a';
5$pos = strpos($mystring, $findme);
6
7// Note our use of ===. Simply == would not work as expected
8// because the position of 'a' was the 0th (first) character.
9if ($pos === false) {
10 echo "The string '$findme' was not found in the string '$mystring'";
11} else {
12 echo "The string '$findme' was found in the string '$mystring'";
13 echo " and exists at position $pos";
14}
15?>
16
17
1<?php
2function g($string,$start,$end){
3 preg_match_all('/' . preg_quote($start, '/') . '(.*?)'. preg_quote($end, '/').'/i', $string, $m);
4 $out = array();
5
6 foreach($m[1] as $key => $value){
7 $type = explode('::',$value);
8 if(sizeof($type)>1){
9 if(!is_array($out[$type[0]]))
10 $out[$type[0]] = array();
11 $out[$type[0]][] = $type[1];
12 } else {
13 $out[] = $value;
14 }
15 }
16 return $out;
17}
18print_r(g('Sample text, [/text to extract/] Rest of sample text [/WEB::http://google.com/] bla bla bla. ','[/','/]'));
19?>
20
21results:
22Array
23(
24 [0] => text to extract
25 [WEB] => Array
26 (
27 [0] => http://google.com
28 )
29
30)
31
32Can be helpfull to custom parsing :)
33