Sesquipedalian Posted January 10, 2008 Share Posted January 10, 2008 I'm posting php to a file, and for some reason right before [Delete Bulletin] it seems to think that I ended the echo I was doing.. when I didn't... whats wrong? I tried multiple different arrangements and uses of the quotes... =/ $content = '<? if ($_SESSION["lvl"] == "1")'. " { echo '<a".' href="?login=deletebulletin&bulletin=$date">'."[Delete Bulletin]</a>'; } ?>"; Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/ Share on other sites More sharing options...
dingus Posted January 10, 2008 Share Posted January 10, 2008 why is the php statment inside its own echo? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-435314 Share on other sites More sharing options...
Sesquipedalian Posted January 10, 2008 Author Share Posted January 10, 2008 technically it's going to be $content = ..... not echo ... (i just fixed it) this was just to see if it would echo it, and it didn't, so i copied and pasted. it was working before, so i don't understand it. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-435323 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 can anyone help...? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436085 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 <?php $content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436103 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 <?php $content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>'; ?> what is the use of <?php ??? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436105 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 <?php $content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>'; ?> what is the use of <?php ??? It defines the start of a block of php code. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436108 Share on other sites More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 Is it necessary to have <?php tags nested like that? ??? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436109 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 yes but take a look carefully $content = is a variable so i supposed you are inside php block and your php tags in that code will be treated as string please let me know if i was wrong is this i typo error or this is really valid? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436110 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 The op wants them to be treated as a string. Read the question. I think the op wants to write php code to a file. eg; <?php $contents = "<?php echo 'this is some php'; ?>"; file_put_contents('newfile.php',$contents); ?> Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436113 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 can you tell me the expected output for that? maybe your right sorry! but the output of that code wont give you what you're expecting try it it html tags has been used < unexpectedly because <?php is treated as string to display try it! Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436115 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 Yes, it's going to be in a file. The thing is, it always seems to get cut off, and it displays [Delete Bulletin]"; } ?>________________ It did that with the code that you provided.. Is there any reason you can think of that it's doing this? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436130 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 use html entities.. your string is treated as html tags because of unwanted use of < $content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>'; echo htmlentities($content); Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436135 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 use html entities.. your string is treated as html tags because of unwanted use of < $content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>'; echo htmlentities($content); No you see I want it to display the link but somehow it gets broken and just displays what I wrote before as text. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436144 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 The code I provided works fine (I just tested it to be sure). If its not working for you you will need to descibe in better detail what it is your trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436148 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 What it did was display the actual php as text. I want it to actually act as php, so if ($_SESSION['lvl'] == '1') it will display that link. it was working before, and i didn't change anything. well its being encrypted but i don't see how that would mess it up. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436158 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 $content = ($_SESSION["lvl"] == "1")?"<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>":''; echo $content; Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436161 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 $content = ($_SESSION["lvl"] == "1")?"<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>":''; echo $content; uhh.. that didn't echo anything. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436163 Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 then it doest match your condition $_SESSION["lvl"] is not equal to 1 Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436167 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 Oh sorry, I didn't have session_start(); I made the encryption a little less, and it still does it, so Ill try to show more code for you guys.. It was working, but when I put it so it will post to the file, it does what my problem at first was. This is the code for when it posts ($content is the content submitted from the form). $newcontent = str_replace('<?', '', str_replace('?>', '', $content)); $delete = ($_SESSION["lvl"] == "1")?"<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>":''; $filename = 'bulletin.txt'; putenv("TZ=America/Denver"); $date = date("D dS M, Y h:i:s a"); $final_en = base64_encode('<b><i>'.$date.'</i></b><br />'.$newcontent.' ' .'<i>-'.$_SESSION['user'].'</i><br />' ."<?php echo $delete; ?>"); $somecontent = ' | '.$final_en; chmod ($filename, 0777); if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file."; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file."; exit; } fclose($handle); echo '<h1>Bulletin Posted </h1><center><a href="index.php">Your bulletin has been posted.</a></center><br /><br />' .'<META HTTP-EQUIV=Refresh CONTENT="1; URL=index.php">'; include ('links.php'); } else { echo "The file is not writable"; } And then this is when I display the file... $file = 'bulletin.txt'; echo '<b>Welcome, you are currently logged in as: </b>'.$_SESSION['user'].'.<br />' .'<b>User level: </b>'.$_SESSION['lvl'].'.<br /><br />'; if (filesize($file) !== 0) { echo '<h1>Bulletins</h1>'; $filename = 'bulletin.txt'; $handle = fopen($filename, 'r'); $read = fread($handle, filesize($filename)); $array = explode(' | ', $read); $i = 0; while ($array[$i] !== NULL) { echo base64_decode($array[$i]); $i++; } if ($_SESSION['lvl'] == '1') { echo '________________<br />' .'<a href="?login=deletebulletins">Delete All Bulletins</a><br /><br />'; } } I think that I could probably just put that part into when I display the files, but it was working before, and it seemed easier. Should I do that, or is there a way to make it actually work..? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436172 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 What exactly is the point? Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436173 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 It's a method of posting a bulletin, the bulletins go encrypted into a file and then are read on the site unencrypted. The bulletins can be posted and deleted by the Administrators. It was working before, and I have no idea why its not anymore. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436176 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 Replace this.... ."<?php echo $delete; ?>"); with... . '<?php if ($_SESSION["lvl"] == "1") {echo "<a href=\"?login=deletebulletin&bulletin=' . $date . '\">[Delete Bulletin]</a>"; ?>'); Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436183 Share on other sites More sharing options...
Sesquipedalian Posted January 11, 2008 Author Share Posted January 11, 2008 It does the same thing as my first problem. Screenshot: Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436189 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 Well, if I write that exact string to a file. eg; <?php $date = date("D dS M, Y h:i:s a"); $content = '<?php if ($_SESSION["lvl"] == "1") {echo "<a href=\"?login=deletebulletin&bulletin=' . $date . '\">[Delete Bulletin]</a>"; ?>'; file_put_contents('file.php',$content); ?> It writes perfectly fine. Quote Link to comment https://forums.phpfreaks.com/topic/85313-stops-echo-when-it-shouldnt/#findComment-436195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.