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

  • Home
  • SEARCH
  • 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

I have a function I've written that was initially supposed to take a string
I had earlier posted a query on Java threads. ( link text ) And
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Initially I had the following: [Flags] public enum QueryFlag { None = 0x00, CustomerID
Initially I had the following: [Flags] public enum QueryFlag { None = 0x00, CustomerID
Ok, so I have an application that reads another processes memory. I initially had
Initially i had x64 bit java sdk and x64 bit STS installed. But then
I recently had to re-factor some code from a previous maintainer and initially I
In my iphone app, I had initially divided the app into modules. Each module
I have multiple apps running which access a sql server database. I had initially

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.