Reputation: 1101
recently I'm developing project via PHP, and today I faced a ridiculous situation, and couldn't get the reason still. So here's my problem
let's suppose that I have a string like this : 'myid(myname)'
what I wanted to get was myid and myname separately, so first I tried it with explode(), and I got result like below:
$order_identity= myid(myname);
$idexplode=explode("(", $order_identity);
$idexplode= Array ( [0] => myid [1] => myname) )
It was good, but not satisfied, because I still have ')' after 'myname' so to get rid of ')'
I used substr() which is very basic built-in php method to slice string value.
$order_name = substr($idexplode[1],0,-1);
and I thought I've done quite good and logged it,However, contrary to my expectations.
I still got 'myname)' when I echoed "echo $order_name
"; !!!
I never met problem like this before and do not know why this happened to me :/.
can you tell me what's going on here and how to solve my problem? thx for reading, your help will be appreciated.
p.s I already checked type and it was string! and also I checked if my php sever being lagged but it wasn't!!
Upvotes: 0
Views: 59
Reputation: 129
use this $order_name - rtrim($idexplode[1],')') Instead of substr()....you get what your want.....hope you got the answer....
Upvotes: 1