checking characters?
Moderator: General Moderators
checking characters?
is it possible to check the first four characters of a string? Well to generalise this,Is it possible to check a buch of characters from a string?
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
you can use preg_match for searching a pattern is available in a string.
you can use preg_replace for replacing patterns with their appropriate patterns.
guess, you should have a look at
http://uk.php.net/manual/en/reference.p ... ifiers.php
you can use preg_replace for replacing patterns with their appropriate patterns.
guess, you should have a look at
http://uk.php.net/manual/en/reference.p ... ifiers.php
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
You may find regular expressions a large hurdle, like most have. That said, you could use a loop over the string to look for your pattern. Here's a start at it:outputs
granted, that example could be done with str_replace() quite easily.
Code: Select all
$string = "hi hi I'm a string!";
for($i = 0, $j = strlen($string); $i < $j; $i++)
{
if($string{$i} == 'h')
{
$string{$i} = 'H';
}
}
echo $string;Code: Select all
Hi Hi I'm a string!granted, that example could be done with str_replace() quite easily.