PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 29, 2021

[FIXED] Reverse the order of letters in the last word in a string

 December 29, 2021     php, replace, reverse, substring     No comments   

Issue

I am trying to reverse the final word in a string.

A multi-word string:

$string = "i like to eat apple";
// to be:  i like to eat elppa

A single word string:

$string = "orange";`
//to be:   egnaro

How can I reverse the order of letters in only the last word -- regardless of how many words are in the string?


Solution

I have been Found the answer. For my own question

$split = explode(" ", $words);
$v_last = $split[count($split)-1]; 
$reverse = strrev($v_last);
$f_word = chop($words,$v_last);
echo $f_word;
echo $reverse;


Answered By - brinardi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing