sicoanimal Posted February 3, 2010 Share Posted February 3, 2010 I am trying to do some text manipulation to allow for include statements to be created from a custom tag in a string. I have got it working but I seem to get a strange character at the beginning of the output from the include. The strange character does not show up on the page (unless I enclose the output in <pre> tags) but is there in the source code, which causes extra spacing between the first two paragraphs. I have included an image of the elusive character as it disappears when I past the source in here. This is my code: $val = "This is a bit of text to go before the script. %SCRIPT(inc.php)% There should be a bit of text from the inc.php file on its own line above."; preg_match('/(.*?)%SCRIPT\(([a-z_.-]+)\)%(.*)/s', $val, $match); array_shift($match); print_r($match); echo "<br><hr><br>"; echo "\n<p>"; $match[0] = str_replace(array("\r\n", "\n","\r"), "<br>", $match[0]); $match[0] = str_replace("<br><br>", "</p>\n", $match[0]); $match[2] = str_replace(array("\r\n", "\n","\r"), "<br>", $match[2]); $match[2] = str_replace("<br><br>", "\n<p>", $match[2]); echo $match[0]; include($match[1]); echo $match[2]; echo "</p>"; inc.php: <?php echo "<p>This is the text in the external file.</p>"; ?> This is the output I get from the script: This is a bit of text to go before the script. This is the text in the external file. There should be a bit of text from the inc.php file on its own line above. Any ideas what it is or why it is showing up? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/190820-strange-character/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.