Re: Pattern Replacing
| From: | Philip Olson | Date: | Thu, 29 Mar 2001 21:25:01 +0000 |
| Subject: | Re: Pattern Replacing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46160@lists.php.net to get a copy of this message | ||
Also consider something like :
<?php
$var = 'a,b,c,';
$var[strrpos($var,',')] = ' ';
print $var; // 'a,b,c '
?>
The idea behind it is similar to this :
<?php
$s = 'abcabc'; // define our string
$s[1] = 'z'; // change second character in $s to 'z'
print $s; // azcabc
$key = strrpos($s,'c'); // 5 (pos of last 'c' in string $s)
print $s[$key]; // c
$s[$key] = 'z'; // change sixth character in $s to z
print $s; // azcabz
?>
Info to know :
strrpos() : Find position of last occurrence of a char in a string
strpos() : Find position of first occurrence of a char in a string
Looks like you found substr() , it helps out for these sorts of things
too :) If anyone has more information on this subject, please post.
Regards,
Philip
On Thu, 29 Mar 2001, Sterling wrote:
> H-
>
> Thanks for the emails and reply.
>
> Someone mentioned substr and after first failing with the attempt I went
> to the PHP site and looked it up.
>
> Here's code that works for what I'm trying to do.
> $test = "tree, bird, nest, ";
> $new = substr($test, 0, strlen($test)-2);
> $new = "$new ";
>
> Appreciate nudges in the right directions.
> -Sterling
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>