Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4574360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:54:44+00:00 2026-05-21T19:54:44+00:00

Initially i had posted a question to find a solution to capitalize every other

  • 0

Initially i had posted a question to find a solution to capitalize every other letter in a string. Thankfully Alex @ SOF was able to offer a great solution, however ive been unable to get it to work with an array… To be clear what im trying to do in this case is explode quotes, capitalize every other letter in the array then implode them back.

if (stripos($data, 'test') !== false) {
$arr = explode('"', $data);

$newStr = '';
foreach($arr as $index => $char) {
$newStr .= ($index % 2) ? strtolower($char) : strtoupper($char);
}

$data = implode('"', $arr);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:54:45+00:00Added an answer on May 21, 2026 at 7:54 pm

    Using the anonymous function requires >= PHP 5.3. If not, just make the callback a normal function. You could use create_function(), but it is rather ugly.

    $str = '"hello" how you "doing?"';
    
    $str = preg_replace_callback('/"(.+?)"/', function($matches) {
      $newStr = '';
       foreach(str_split($matches[0]) as $index => $char) {
           $newStr .= ($index % 2) ? strtolower($char) : strtoupper($char);
       }
       return $newStr;
    
    }, $str);
    
    var_dump($str);
    

    Output

    string(24) ""hElLo" how you "dOiNg?""
    

    CodePad.

    If you want to swap the case, swap the strtolower() and strtoupper() calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For this assignment I had to create my own string class. I initially wrote
I posted this question on the django-users list, but haven't had a reply there
Since the way I had initially written my question received some down votes, and
I initially had the following code: Boolean successCheckPoint = false; Boolean failureCheckPoint = false;
I've initially had two branches: master A---B---C \ fork D---E---F---H---I So I wanted to
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Initially I had designed this flash based navigation menu for my website, after going
Initially I had the habbit of directly writing the php code in the <?php
Initially I had a method in our DL that would take in the object
My code base initially was written in ruby. It had a rakefile.rb file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.