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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:00:04+00:00 2026-05-11T12:00:04+00:00

i have a string with double quote like this $count = 5; $str =

  • 0

i have a string with double quote like this

$count = 5; $str = 'result: $count'; echo $str; //result: 5 

variable parsing work well, and my problem is $count var must be define later than $str

$str = 'result: $count'; $count = 5; echo $str; //result: 

So i will use single quote and ask a question here to finding a way to parse var whenever i want

$str = 'result: $count'; $count = 5; //TODO: parse var process echo $str; //result: 5 

I’m will not using regex replace.

  • 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. 2026-05-11T12:00:05+00:00Added an answer on May 11, 2026 at 12:00 pm

    For this type of thing, I’d probably use string formatting. In PHP, that’d be printf.

     ?php $str='result: %d' ....dostuff.....define $count..... printf($str,$count) ? 

    edit: although, the best way to do this probably depends partly on why you have to define $string before $count.

    If it’s a string that’s repeated a lot, and you wanted to put it in a global variable or something, printf would be my choice, or putting it in a function as other answers have suggested.

    If the string is only used once or twice, are you sure you can’t refactor the code to make $count be defined before $string?

    finally, a bit of bland theory: when you write ‘$string = ‘result: $count”, PHP immediately takes the value of $count and puts it into the string. after that, it isn’t worried about $count anymore, for purposes of $string, and even if $count changes, $string won’t, because it contains a literal copy of the value. There isn’t, as far as I’m aware, a way of binding a position in a string to a yet-to-be-defined variable. The ‘printf’ method leaves placeholders in the string, which the function printf replaces with values when you decide what should go in the placeholders.

    So, if you wanted to only write $string = ‘result: $count’ $count=5 $echo string

    (and not have to call another function)

    and get ‘result: 5’, there’s no way to do that. The closest method would be using placeholders and printf, but that requires an explicit call to a function, not an implicit substitution.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to manipulate the DOM ala Jquery, PHPQuery… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer Recent versions of GCC have a way to report which… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer Write a little bit of javascript on the page to… May 11, 2026 at 11:48 pm

Related Questions

I am having problem with escaping the single and double quotes inside the href
I have a Windows batch file I'm creating, but I have to ECHO a
I need to echo a string containing angle brackets (< and >) to a
When you execute a SQL query, you have to clean your strings or users

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.