This is a question from stackoverflow (link http://stackoverflow.com/questions/35122231/mysql-how-to-get-numeric-value-after-special-character-in-varchar)
I have a string of records, how can I get the rightmost value (1, 2, 10) after the slash "/" in this string of records. It would be great if you have PHP code that can automatically reset the month value.
Answer:
Assuming you know that all records are in the form of A/x/y, and "/" is always used as a special symbol, then you can use explode()
Code:
substring_index(): select substring_index(col,'/',-1) <br>
from t;
If you want to turn the obtained t
into a number select substring_index(col,'/',-1)+1 <br>
from t;
Second answer:
Try this: $str = "ABC/209116/1"; <br>
$replace_with = "0"; <br>
$str= substr(0,strrchr($str,"/")); <br>
$replace_with;
The above introduces how MySQL obtains the value after the special character in a variable-length string (from stackoverflow), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.