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

Wednesday, December 29, 2021

[FIXED] Reverse the direction of all sequences of letters in a string

 December 29, 2021     php, reverse, substring     No comments   

Issue

Is it possible to reverse only the letters in a string?

For instance if I have the word $word = "word,!";

I need the result to be $result = "drow,!";

I tried using strrev, but it reverses the punctuation marks too.


Solution

 $word = "word,!pineapple--pizza";
 $revd = preg_replace_callback('#([A-Za-z]+)#', 'rev_first', $word);

function rev_first($matches){
    return strrev($matches[1]);
}

http://3v4l.org/PXEs8

Is this what you're looking for?



Answered By - scragar
  • 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