Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How to Find a Substring from a Given String
How to Find a Substring from a Given String? - PHP Script Tips - PHP Built-in Functions for Strings
✍: FYIcenter.com
To find a substring in a given string, you can use the strpos() function. If you call strpos($haystack, $needle), it will try to find the position of the first occurrence of the $needle string in the $haystack string. If found, it will return a non-negative integer represents the position of $needle. Othewise, it will return a Boolean false. Here is a PHP script example of strpos():
<?php
$haystack1 = "2349534134345fyicenter16504381640386488129";
$haystack2 = "fyicenter234953413434516504381640386488129";
$haystack3 = "center234953413434516504381640386488129fyi";
$pos1 = strpos($haystack1, "fyicenter");
$pos2 = strpos($haystack2, "fyicenter");
$pos3 = strpos($haystack3, "fyicenter");
print("pos1 = ($pos1); type is " . gettype($pos1) . "\n");
print("pos2 = ($pos2); type is " . gettype($pos2) . "\n");
print("pos3 = ($pos3); type is " . gettype($pos3) . "\n");
?>
This script will print:
pos1 = (13); type is integer pos2 = (0); type is integer pos3 = (); type is boolean
"pos3" shows strpos() can return a Boolean value.
2007-04-21, 5604👍, 0💬
Popular Posts:
How was XML handled during COM times? During COM it was done by using MSXML 4.0. So old languages li...
Rachel opened her math book and found that the sum of the facing pages was 245. What pages did she o...
Which JavaScript file is referenced for validating the validators at the client side ? WebUIValidati...
What is a fish bone diagram ? Dr. Kaoru Ishikawa, invented the fishbone diagram. Therefore, it can b...
An application needs to load a library before it starts to run, how to code? One option is to use a ...