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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:08:55+00:00 2026-05-13T23:08:55+00:00

I’m having a problem with some code that used to work in PHP 4.X

  • 0

I’m having a problem with some code that used to work in PHP 4.X and is not working in PHP 5.2.4

First of all, there is a small example of a code similar to the one is causing the problem. Unfortunately, I haven’t been able to reproduce the problem with a small example.

<?php
class Example{

  public function showExample()
  {
    $ind = 1;
    $m   = "method";
    $str2 = "{call method}";

    $str2 = str_replace("{call $m}" , "<?php  print( \$pre$ind ); ?>", $str2);

    echo $str2 . "\n";
   }
}

$e = new Example();
$e -> showExample();
?>

What this code is doing is building a string with some php code to execute later on. In particular, the code generated will print the value of a variable named “$pre” + a variable number. In this case, the output is the following:

 <?php  print( $pre1 ); ?>

Everything runs fine with this code. The problem is when I use it in the context of a much bigger class, that is part of a framework I’ve been using for a long time. I cannot paste here the whole source of the class, but the problematic lines are the following (I simplified them a little bit to remove the str_replace, but the error still appears):

        $myVar = "value";
        $myVar2 = 2;
        $str2 = "<?php print( \$myVar$myVar2 );  ?>";

When I load the file, I get the following two messages:

PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1 in /Users/giove/Sites/mundial/htmltemplate.php on line 252
PHP Parse error:  syntax error, unexpected T_VARIABLE in /Users/giove/Sites/mundial/htmltemplate.php on line 252

I can fix the warning by removing the ‘\’, but that changes the semantics of the code, so it’s not a real possibility.

Now, the weirdest part is I can remove both errors by breaking or removing the sequence ”

This seems to be a difference in versions, but I haven’t been able to find any mention to it on the change logs.


Now I’ve got a working solution from Cryo: split the string

 "<?php" 

to prevent its ‘evalution’ (I’m not sure if that’s really an evaluation).

Nevertheless, I still would like to know the reason for this weird behavior.

Cryo: thanks for your help, I’ll mark the question as answered in a couple of days.

  • 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-13T23:08:56+00:00Added an answer on May 13, 2026 at 11:08 pm

    My guess is that PHP is catching on the re-opening of the php tag <?php, try splitting just that:

    $str2 = "<?" . "php print( \$myVar$myVar2 );  ?>";
    

    Or use single quotes and concatenation:

    $str2 = '<?php print( $myVar' . $myVar2 . ' );  ?>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your stack trace indicates the ModalWindow createAttentie is not part… May 14, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer The (+) is Oracle specific pre-ANSI-92 OUTER JOIN syntax, because… May 14, 2026 at 12:02 am
  • Editorial Team
    Editorial Team added an answer I have had this problem too. You will need to… May 14, 2026 at 12:02 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

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.