2

I am removing the first character of the string and I am using substr(); function for that.
For example :

<?php
$amount =  '€300';
echo substr($amount ,1);
?>

This code is doing its work fine but it have some bug. When I display the substr() function applied string then it display something other symbol at the beginning of the string. Below image has output.enter image description here

In above image you can see its displaying unwanted symbol. But when I apply substr() function again it works successfull.
I just want to know why this function having that symbol? what does this symbol mean? Why its coming in the output?

4
  • Seems to work fine in PHPFiddle too. Commented Oct 3, 2015 at 8:59
  • 3
    This probably is an issue with your php setup, your configuration. This looks as if you are trying to apply the 8 bit function to a utf encoded string which certainly will not work.Please read about unicode support in php and about the mbstring extension and "function overloading"`. Commented Oct 3, 2015 at 8:59
  • The problem seem to happen with the symbol but not with $ Commented Oct 3, 2015 at 9:00
  • 1
    This happens when you strip a byte of a multibyte character. You should use multibyte-aware string functions (mb_*) for multibyte-encoded strings (e. g. UTF-8). stackoverflow.com/questions/9087502/… Commented Oct 3, 2015 at 9:15

2 Answers 2

2

you could using mb_substr() php function http://php.net/manual/en/function.mb-substr.php

<?php
$amount =  '€300';
echo mb_substr($amount, 1, NULL, "UTF-8");
?>
Sign up to request clarification or add additional context in comments.

Comments

1

I managed to solve the problem by using utf8_decode, i.e.:

$amount =  utf8_decode('€300');
echo substr($amount ,1);
//300

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.