PHP not executing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

eval('return "'.str_replace('"','"',$msg).'";');
I think...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

bump (to fix the replies count)
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

do, it should be:

Code: Select all

<?php 

include('admin/header.php'); // get connection information 

$row = mysql_fetch_array($rs); 
$msg = $row['public'];

eval('return "'.str_replace('"','"',$msg).'";');

include('admin/strings.php'); 

echo($msg); 

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$output = eval(.....);
echo($output);
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Warning: Wrong parameter count for str_replace() in /home/host/public_html/index.php on line 14

I'm guessing that cant be good :\
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmm... I wrote the correct number of arguments...
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Code: Select all

<?php

$msg = <<<EOS
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test</title>
</head>

<body>



<div align="center"><?php echo"test"; ?></div>


</body> 
EOS;

$msg = eval('?>' . $msg);

echo $msg;

?>
Works for me. I can also replace...

Code: Select all

$msg = eval('?>' . $msg);

echo $msg;
...with just.....

Code: Select all

eval('?>' . $msg);
If I wanted to the code to execute at that particular point in the script.

Note, I had to use standard code tags to stop the forum removing the '?>' with the snippet.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

How did you get it to work, whenever i tried it, it came up with an error, and so did one of my friends.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

I just ran the code snippet I supplied above.

Care to share the error message(s) you are getting?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

The was the code that i was using:

Code: Select all

<?php 

include('admin/header.php'); // get connection information 

$row = mysql_fetch_array($rs); 
$msg = $row['public']; 

$msg = eval('return "',str_replace('"','"'.$msg).'";'); 

include('admin/strings.php'); 

echo($msg); 

?>
And $msg contains this:

Code: Select all

<html> 

<head> 
<meta http-equiv="Content-Language" content="en-gb"> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
<title>Test</title> 
</head> 

<body> 



<div align="center"><?php echo"test"; ?></div> 


</body>
The error that I get is: Parse error: parse error in /home/host/public_html/index.php on line 14
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

str_replace('"','\"'.$msg)
should be
str_replace('"','\"',$msg)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Archy wrote:The was the code that i was using:

Code: Select all

<?php 

include('admin/header.php'); // get connection information 

$row = mysql_fetch_array($rs); 
$msg = $row['public']; 

$msg = eval('return "',str_replace('"','"'.$msg).'";'); 

include('admin/strings.php'); 

echo($msg); 

?>
That's not the code snippet I offered.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

redmonkey, what was the exact code you used for in the database, and on the actual page it's self, as I am still having dificulties with this.
Post Reply