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 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

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I know there's a lot of other questions out there that deal with this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.