By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Wiki style text input

P: n/a
I have a text file called test.txt which is I am trying to get to load
into a webpage. This is simple enough, but I am trying to make it so
that it recognises certain formatting, similar to how wikipedia pages
work.

so, my text file contains ONLY the following:

This is /just/ some test text *to see* if the PHP works
and to /*evaluate*/ what it actually does

The intention is that /just/ will show as italic, *to see* will show as
bold and /*evaluate*/ will show as bold italic.

Creating the text inside the page works fine.

<?php
$s = 'hello. /this/ works *bolding* works. /*Both work*/!';
$search = array ( '@/(.*?)/@si',
'@\*(.*?)\*@si');
$replace = array ( '<i>\1</i>',
'<b>\1</b>');

echo preg_replace($search, $replace, $s);

?>

However when I try and read from a text file using

$s = file('./wiki.txt');
$search = array ( '@/(.*?)/@si',
'@\*(.*?)\*@si');
$replace = array ( '<i>\1</i>',
'<b>\1</b>');

echo preg_replace($search, $replace, $s);

?>

All that is shown is the single word 'Array'. This confuses me a lot as

<?
$s = file('./test.txt');
print_r($s);
?>

shows that the text is being read into the page
Array ( [0] => This is /just/ some test text *to see* if the PHP works
[1] => and to /*evaluate*/ what it actually does )

If someone can see what is going wrong here I would be most grateful.

Kind regards

Dan

Jun 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dan Pearce wrote:
<snip>
However when I try and read from a text file using

$s = file('./wiki.txt');
$search = array ( '@/(.*?)/@si',
'@\*(.*?)\*@si');
$replace = array ( '<i>\1</i>',
'<b>\1</b>');

echo preg_replace($search, $replace, $s);

?>

All that is shown is the single word 'Array'. This confuses me a lot as

<snip>

file() returns array <http://in2.php.net/file>. You may want
<http://in2.php.net/file_get_contents>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jun 20 '06 #2

P: n/a
Try use this instead of using file()
Note: not compatible with php3
<?php
$s = file_get_contents('./test.txt');
?>

Jun 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.