note 120052 added to function.strrpos
| From: | stevewa | Date: | Mon, 17 Oct 2016 19:25:22 +0000 |
| Subject: | note 120052 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206908@lists.php.net to get a copy of this message | ||
i wanted to find a leading space BEFORE a hyphen
Crude Oil (Dec) 51.00-56.00
so I had to find the position of the hyphen
then subtract that position from the length of the string (to make it a negative number)
and then walk left toward the beginning of the string, looking for the first space before the hyphen
ex:
$str_position_hyphen = strpos($line_new,"-",$str_position_spread);
$line_new_length = strlen($line_new);
$str_position_hyphen_from_end = $str_position_hyphen - $line_new_length;
echo "hyphen position from end = " . $str_position_hyphen_from_end . "<br
/>\n";
$str_position_space_before_hyphen = strrpos($line_new, " ",
$str_position_hyphen_from_end);
echo "*** previous space= " . $str_position_space_before_hyphen . "<br
/>\n";
$line_new = substr_replace($line_new, ",", $str_position_space_before_hyphen, 1 );
echo $line_new . "<br /><br />\n";
----
Server IP: 72.52.91.14
Probable Submitter: 67.255.35.203
----
Manual Page -- http://php.net/manual/en/function.strrpos.php
Edit -- https://master.php.net/note/edit/120052
Del: integrated -- https://master.php.net/note/delete/120052/integrated
Del: useless -- https://master.php.net/note/delete/120052/useless
Del: bad code -- https://master.php.net/note/delete/120052/bad+code
Del: spam -- https://master.php.net/note/delete/120052/spam
Del: non-english -- https://master.php.net/note/delete/120052/non-english
Del: in docs -- https://master.php.net/note/delete/120052/in+docs
Del: other reasons-- https://master.php.net/note/delete/120052
Reject -- https://master.php.net/note/reject/120052
Search -- https://master.php.net/manage/user-notes.php