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 7642409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:10:58+00:00 2026-05-31T09:10:58+00:00

I am using PHPs’ strtr method to replace certain tokens/placeholders in a string. This

  • 0

I am using PHPs’ strtr method to replace certain tokens/placeholders in a string. This works very well but now I’m trying to work out if all of my tokens were replaced.

The following example:

$trans = array(":hello" => "hi", ":hi" => "hello");
echo strtr(":hi all, I said :hello", $trans);

will output:

hello all, I said hi

Both tokens were replaced successfully but how do I check this. I can’t search the output for occurrences of my delimiter ‘:’ since the output string could contain valid ‘:’ in the data.

Is there a way that I can escape these delimiters before doing the replace, then do a count on the unescaped delimiters to see if there were any token left unreplaced, and then finally unescape the escaped delimiters before returning?

NOTE: I cannot use str_replace, this method needs to be used.

  • 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-31T09:10:59+00:00Added an answer on May 31, 2026 at 9:10 am

    I don’t think strtr can help you here, it just replaces whatever it finds. What you seem to want is to figure out if there is a difference between the tokens in the array and in the string. For that, something like this should do:

    preg_match_all('/:\w+/', $str, $matches);
    if (array_diff($matches[0], array_keys($trans))) {
        // the string has tokens that aren't in $trans
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this PHP class for a Twitter script: twitter.slawcup.com/twitter.class.phps The script is: $t=
I'm currently using php's imagick to convert some PDF to images - This works
I wish to send an email from my localhost machine (using PHPs mail function)
I'm creating an dynamic image, which creates headers on my page using PHPs GD-library.
Using PHP's Image and GD functions you can use the following method to finally
I'm using PHP's DOMDocument to parse and normalize user-submitted HTML using the loadHTML method
This piece of valid json (it has been generated using php's json_encode): {html:form is
I have a string that contains this (and another things): <b>SINOPSIS:</b><br/> Text text text
I have an IE problem. I am using the jquery ajax method to call
Is there a difference between using PHPs time() and using new MongoDate() ? I

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.