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, 5199👍, 0💬
Popular Posts:
How can you enable automatic paging in DataGrid ? Following are the points to be done in order to en...
How can we format data inside DataGrid? Use the DataFormatString property.
How To Control Horizontal Alignment? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells By...
What is the benefit of using #define to declare a constant? Using the #define method of declaring a ...
How can I check for HTML errors? HTML validators check HTML documents against a formal definition of...