2010-10-05 21:44:30 +02:00
|
|
|
<?php
|
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2010-10-05 21:44:30 +02:00
|
|
|
*
|
|
|
|
* (c) Christian Kerl <christian-kerl@web.de>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\Util;
|
2010-10-05 21:44:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* String provides utility methods for strings.
|
|
|
|
*
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
|
|
|
class String
|
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
/**
|
|
|
|
* Checks if a string starts with a given string.
|
|
|
|
*
|
|
|
|
* @param string $str A string
|
|
|
|
* @param string $substr A string to check against
|
|
|
|
*
|
|
|
|
* @return bool True if str starts with substr
|
|
|
|
*/
|
2011-07-14 17:45:03 +02:00
|
|
|
public static function startsWith($str, $substr)
|
2010-10-05 21:44:30 +02:00
|
|
|
{
|
2011-07-14 17:45:03 +02:00
|
|
|
if(is_string($str) && is_string($substr) && strlen($str) >= strlen($substr)) {
|
|
|
|
return $substr == substr($str, 0, strlen($substr));
|
|
|
|
}
|
2010-10-05 21:44:30 +02:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:45:03 +02:00
|
|
|
/**
|
2011-07-17 10:46:54 +02:00
|
|
|
* Checks if a string ends with a given string.
|
|
|
|
*
|
|
|
|
* @param string $str A string
|
|
|
|
* @param string $substr A string to check against
|
|
|
|
*
|
|
|
|
* @return bool True if str ends with substr
|
|
|
|
*/
|
2011-07-14 17:45:03 +02:00
|
|
|
public static function endsWith($str, $substr)
|
2010-10-05 21:44:30 +02:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
if(is_string($str) && is_string($substr) && strlen($str) >= strlen($substr)) {
|
2011-07-14 17:45:03 +02:00
|
|
|
return $substr == substr($str, strlen($str) - strlen($substr));
|
|
|
|
}
|
2010-10-05 21:44:30 +02:00
|
|
|
}
|
|
|
|
}
|