Jump to content

ignore first character and display the rest


sungpeng

Recommended Posts

$hello="category American apple";

echo end(explode(' ', $hello));

 

The above code can display the last wordings "apple".

 

I also need a code to ignore the first wordings and display the rest. In this case, it will display "American apple" and ignore "category".

the substr() function would probably help you out. This function takes three parameters, the string, the start point and the length, the latter which is optional.

 

If you did the following code

 

$text = "Hello World";
$text = substr($text, 0, 5);
echo $text;

 

you would output hello. If you want to take off the first letter, then you want to take the substring starting with the second character right?

so the following code:

$hello="1 fish meat rice";
$hello = substr($hello, 1);
echo $hello;

 

would do what you want because it takes everything from the 2nd character (or the character with position 1) on

 

Hope that helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.