How to get specific string from string in php? I have one string "Hello", so I want only "He". How is it possible with function or other method?
Asked
Active
Viewed 84 times
-2
-
2Google: `PHP substr()` – Rizier123 Dec 17 '15 at 13:46
-
I'm new so please explain details. please give any example. – Hiren Kukadiya Dec 17 '15 at 13:46
-
3`not any answer on web` - you're kidding me – Mark Baker Dec 17 '15 at 13:47
-
3There are plenty of questions similar to yours, it's not our job to teach you, Rizier123 gave you a hint, google it and you'll find plenty of explanations and examples. – Epodax Dec 17 '15 at 13:47
-
no no but not specific any answer may i can't understand that. – Hiren Kukadiya Dec 17 '15 at 13:48
-
Just detail more your question. Do you always wants the 2 firsts characters of a string? – JonathanG Dec 17 '15 at 13:48
-
no i want string that i entered. – Hiren Kukadiya Dec 17 '15 at 13:49
-
[Simply scroll down to the link and you'll find **lot of examples** over there.](http://php.net/manual/en/function.substr.php) – Narendrasingh Sisodia Dec 17 '15 at 13:51
-
ok i will try for that and so many thanks. Uchiha – Hiren Kukadiya Dec 17 '15 at 13:52
1 Answers
0
You should learn about string functions.
<?php
$startPosition = 0; // INITIALIZE FROM WHICH POINT YOU WANT TO TAKE CHARACTERS
$characters = 2; // INITIALIZE NUMBER OF CHARACTERS YOU REQUIRED
$string = 'Hello'; // INITALIZE YOUR STRING
$string1 = substr($string, $startPosition, $characters); // STRING FUNCTION
?>

Anto S
- 2,448
- 6
- 32
- 50