473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Wiki style text input

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
2 1473
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
Try use this instead of using file()
Note: not compatible with php3
<?php
$s = file_get_contents('./test.txt');
?>

Jun 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kenneth McDonald | last post by:
I'm looking for a Wiki engine to set up for my company, so that we can incrementally add user documentation for a fairly complex program, plus allow users to add their own comments for the benefit...
6
by: Andrus | last post by:
I want that if user clicks in a checkbox, the strike-through effect applices to current table row. I tried the following code in IE, but nothing happens. Any idea ? <table> <tr><td><input...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
5
by: Ben | last post by:
I have a form for data entry which is in a table. I have a select box to enter a customer name, which takes it's options from the customer database. I have a button to add a new customer. What I...
65
by: Giannis Papadopoulos | last post by:
Although Steve Summit's C FAQ is really good, are there any C FAQ wikis? -- one's freedom stops where others' begin Giannis Papadopoulos http://dop.users.uth.gr/ University of Thessaly...
302
by: Lee | last post by:
Hi Whenever I use the gets() function, the gnu c compiler gives a warning that it is dangerous to use gets(). Is this due to the possibility of array overflow? Is it correct that the program...
8
by: Mike S | last post by:
Hi all, I noticed a very slight logic error in the solution to K&R Exercise 1-22 on the the CLC-Wiki, located at http://www.clc-wiki.net/wiki/KR2_Exercise_1-22 The exercise reads as...
1
by: Armin Gajda | last post by:
Hi, I have the following problem: An input field get a border assigned by a style class (e.g. 2px solid red). When the field gets the focus, we set the border to green. element.style.border...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.