Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.