Rated an average of 0 stars by 0 people

Check If a String Starts with a Specific Pattern

Script Details:
Added on December 19, 2010 by Zhay.
Zhay accreditted the script to "http://snipplr.com/view.php?codeview&id=2143."

Description:
Some languages such as Java have a startWith method/function which allows you to check if a string starts with a specific pattern. Unfortunately, PHP does not have a similar built-in function. Whatever--we just have to build our own, which is very simple.

Tags: beginning, pattern, starts, string, with

Code:

<?php
# Snippet from PHP Share: http://www.phpshare.org

function strBeginsWith($needle$haystack
{
    return(
substr($haystack0strlen($needle)) == $needle);
}
?>

Review this PHP Script:

Rating:

Comments:


Login

User:
Pass:

Register

Not a member? Register today and receive the many free benefits of being a member!

Advertisements