Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Append Text At End Of Existing Text On Same Line


I'm working on a part of my web site that uploads images, then writes the name of the image to a text file. The upload part works fine. The part that writes the name of the image to the text file works fine.

What I'm trying to do is, after all the files have been uploaded and all of the image names have been written to the WriteTo.txt file, append a written description of the picture at the end of the picture name. In other words, after a user uploads their pictures to the server I want to direct them to a page where they can label each of the pictures using a form. PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Writing To Existing Text File
I am having some problems writing to a file that already exisits. I can create a new file and write to it, but when I try to write to that file later it fails.

When a form is submitted the text from that form is to be written to a file. The user is then redirected to a page advising of the outcome of the submit. IE Success, data written, Failure (The file could not be opened) or Failure (The file could be opened, but not saved). Code:

Delete Entire Line In Text File If Anything In The Line Matches Search String
how would I code a php script that would open a text file, look for a string i specified, and if it finds that string, it will delete the entire line in the text file that contained that text. I'm new to php, so sorry if this is really obvious..

How To Return Just First-line From A Multi-line String Of Text?
I've been looking through the manual for string commands, and I haven't had success in determining the proper call for this, if there is one:

Let's say I have a text string with hard-carriage returns in it:

"The lazy brown fox ran down the road
to the store and bought some eggs
to bake a cake and serve dinner
for all his friends."

So if that string value is in "x", how can I tell it to return JUST the first line: "The lazy brown fox ran down the road"

Read Text File Line By Line
I have been given a textfile which contains data on 1000 businesses.  Each line contains a name and a code which are seperated by a comma.  The code below allows me to display the entire textfile but I want to read in the values from each line and store these in a database.

$filename = "businesses.txt";
$fileToOpen = fopen($filename,"r");
$content = fread($fileToOpen, filesize($filename));
$content = nl2br($content);
fclose($fileToOpen);
echo($content);

Does anyone know how I can read the data in line by line so that I can store it in a database.

Line Break In Text Box To < Br >
I made a little form that allows me to post news. When submit is hit, it just writes to an html file. I want to know, if i make a line break in the text box when im entering news, how can i make that carry over to a < br > tag.

Line Return In Text Box
I have a text box where users type whatever. Anyways, I am using stripslashes() and posting the contents to mysql table as TEXT. Every where I have used br it echos the newline plus rn, which i assume is supposed to be with the slashes removed.

So I don't have to input br everytime I press enter, how can I catch when the enter key is pressed and output a new line, like the way this forum is doing it?

Selecting A Line Of Text
I'm trying to display a bunch of lines of text one line at a time, like a code printout, and allow the user to select one of the lines by clicking on it. Obviously, the displaying part isn't so hard. But i'm not sure how to select and highlight a whole line with a single click, or how to figure out which line has been selected afterwards. How does one normally do something like this?

New Line In Text File
I'm trying to create a text file in php to generate a playlist. The problem is that I cannot manage to create a new line in the text file. Using /n still places text in the same line and just inserts a symbol to indicate the 'new line'. Using

just works when viewing the document in HTML (which is not what i need in this case). But what I want is to physically insert a new line in the text file so that when i open the generated file using notepad i see that there are actually new lines in the document and so that the playlist can be read normally with a music player.

How Can A Line Be Deleted From A Text File
Since, I cannot seem to delete the last line in a text database using the code below.

What other way can I delete a line from a text file?

How To Edit A Line In A Text File
i have a text file (just testing php) which stores about 10 lines where each line represents a user request. how do i edit that line to allow the user to edit the $bookwanted ? the lines below shows my display info for the user.

$file=file('logindata.txt');

foreach($file as $line){
list($bookwanted,,$user,$pass,$acct,$email,$amt,$date)=explode('|',$line);

if (($username == $user) && ($password == $pass) ) {

// display info for that particular user

}

All Text Email - How Do You Add Line-breaks?
Sending an all text email through php.

How do I put line breaks in the message, I was unable to google it

I know you can use "", but like, what else can I do, what is this stuff even called, language, so I can find out what the stuff does?

How To Capture The First Line Of A Text, Then The Rest?
How can I cath the first line of a .txt file or whatever in PHP, using include("")? I need it for this, like, I'm thinking of doing a site with reviews on it, and I want to have one .php file for all the reviews. So that I can open a review using review.php?review_id=photoshop6

Im planning to have each review as one txt file, that I write "by hand" with the first line as the title. (If anyone knows of a better, smarter and faster way to do this, let me know, i'm new with PHP. With MySQL or whatever.)

The script should first parse the first line of the .txt file and use that one for title, so i can use a different size of text for it, and then it should parse the rest of the file and use for body text.

Random Line From Text File
I want to grab a random line from a flat file and then echo it. I could probably do this but the alcohol prevents me from thinking.

Read Line From Text File
I have a text file that i would like to use PHP to read from. each line
ends with a. I need to read from the beginning of the line, only upto that:

right now i'm using this, which is sloppy and slow:

if ($chr = fgetc($file)) != "") { }

which of course reads in one byte at a time till the end of line. is there
a better way?

Replace A Line In A Text File
I would like to replace a single line in a text file. The initially i only had to have a single line so I could just use fputs to rewrite the entire file.  Now I have three lines and want to selectively replace one of them..

Detect Line From Text File
I have a text file that list out several activation code
aaaaa1
aaaaa2
aaaaa3
aaaaa4
aaaaa5
Then I will create a form which user will enter the line number of the text file to get the activation code. Eg user enter '2', so the system will pop out 'aaaaa2'.

The Problem is I really stuck on how to get php call the line number in the text file.

Reading Strings In Text File (1 Per Line)
I am trying to take a text file containing a list of email addresses (1 per line), and insert each line as a new item in mySQL.

I know how to do most of the php and the mySQL, but I am not sure about the syntax of the line to return the string from "line x" of the tex tfile.

From the php doc. I have this code to read the full contents of my text file:

// get contents of a file into a string
$filename = "/usr/local/something.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);

My question, clearly is:
then how do I split $contents into an array so that $emails[150] could return the email number 150?

Detecting Line Breaks In A Text Area?
This is really frustrating... I have a form in which there is a text area for people to post comments on the site. I'm hoping that people will take the time to fill out reasonable length responses which my spread over two or more paragraphs. My problem lies there; it might spread over two paragraphs...

I know I can use 'special character(s)' which the user can put in that I can then do a ereg_replace() to put the <p> or <br> tags in but I would prefer that they didn't have to... like for instance in this forum

I've tried to see whether there are any line breaks or something in the textarea when a carriage return has been made but I can't seem to pick anything up, has anybody managed to come up with a solution to this?

Deleting A Line Of Text From A Txt File From A Form
How can i delete a line of text from a .txt file using a form?

because i have a form right now that saves information from a form to a txt file for news, now i need to know how to make it so i can delete it from a form.

also, if you know how, how do you overwrite lines of text in txt files from a form?

Appending Text To A File, Starting A New Line.
Im appending text to a file. And I'd like each 'append' would start on a new line of a file. I tried 'n'. but it doesnt work. here is my code:

$fp = fopen("$filename", "a");
for ($i = 0; $i < count($arrText); $i++){
fputs($fp, $arrText[$i]);
} fclose($fp);

note: one of the array $arrText, eg. $arrText[3] = "line 3" . "n";
the next array $arrText[4] will NOT start on a new line, it will just joint the rrText[3].

Is There A Php Command To Take A Specific Field From A Delimited Line Of Text?
I have a string which is multiple fields delimited by commas.

I would like a php command that says... take the 3rd field for
example.

ie. If MYVARIABLE has the data "hello,there,big,world".

I would like to be able to say, pickup the 3rd field "big" without
knowing the character positions or lengths.

Removing Line Breaks In Reading Text File
When I read in a text file seperated by | delimiter, all is well except in the case of data posted to that text file from a Textarea within a Form. When the user hits the Return key once, a new line is ultimately created in the final file read; when the user does a 2nd or subsequent CR, there are multiple blank lines on the file as it is echoed into a web page (in fact, 7 <BR>s in a row).

I've tried str_replace to no effect ...is it a PHP error or is it something logical I've missed. Lines 5a, 5b, 5c, 5d are the results of a Textarea submission - they aer all one field - that have been seperated by a carriage return in an html form posting to a text file: Code:

How To Echo A Single, Specific Line From A Text File
How do I echo a single, specific line from a text file?  Let's say, for example, the second line?

Line Feeds With MIME-Version: 1.0Content-Type:text/html; Charset=iso-8859-1
I added "MIME-Version: 1.0
Content-Type:text/html;
charset=iso-8859-1
" as one of the parameters in the mail( )
function to replace the "Nobody" with a real From: email. That worked.

But if I attempt to add any other terms, such as the sender's name and
location, the MIME parameter above seems to ignore the "
" line feeds
and put the these other terms ahead of the mail message.

Here's my code:

mail("$toaddress", "$subject", "$mailcontent", "MIME-Version:
1.0
Content-Type:text/html; charset=iso-8859-1
From: ".
$youremail
. "
" . $yourname . "
");

The value for $yourname appears ahead of the message [$mailcontent] on
the same line. What I would like it to do is display the message, go
to a new line, then display $yourname.

Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Gaining Access To How MySql Parses Text For Full Text
I want to gain access to the function or process MySql uses to parse words and phrases for Full Text searching. Here is an example.

If the user inputs...

Milan in history

MySql will search for milan, history, and milan history. Is there a way to extract just the combination of terms MySql uses to search the db without the stop words? Stop words are automatically eliminated from the search request unless the user encloses a phrase in quotes.

What I am trying to do is develop a script to highlight found search terms and phrases. I can explode a phrase into single words but if I do that the stop words would be included in the array. If there is some way of getting into the parsed words or phrases MySql Full Text actually uses to search, I can use each of those combinations as a keyword in my highlighting script.

This request is about searching for the code or any code related to the questions involved.

Text Area Not Accepting Large Amounts Of Text
I have a form where teachers enter homework assignments and they are then stored in a MYSQL database and retrieved elsewhere.

I have been using "get" with the form. The code is simple:

<textarea name="array[assignment]" cols="60" rows="10" id="array[assignment]"></textarea>

It does allow post of 100 words, etc. Stuff that teachers normally submit.

What's happening is that it won't allow very large posts (over 300 words maybe? ) Not sure what the cut off is. When you press submit it won't go, or there is an error where it won't submit.

Is there a limit for text fields? Since the fields scroll, I didn't think that having only 60 rows was any type of real limit, I though you could put in as much as needed. But then all of it ends up in the address bar, so there must be a limit of some sort.

Imagettftext() Gives Grainy Text When Writing Aliased Text
I'm using a bundled version of GD: 2.0.23 compatible. When using the
function imagettftext() with a negative color to get a aliased text,
the text gets grainy. What could be wrong? I've tried several ttf
fonts, with the same result.

Read And Display Japanese Text From Text File
I posted a question regarding reading japanese
text from a text file.

Well, since I solved the problem, I thought I'd post my solution for
the benefit of other people with the same problem.

The plan was to make a script to read and display japanese text. I
will use it for making a japanese proverb script and for a japanese
language study script.

Method :

I wrote a simple kanji text file (saved with UTF-8 encoding)
I wrote a simple PHP script to display the file contents (saved with
UTF-8
encoding)
I specified the content-type header for the HTML page :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

*** All files have the same encoding. ***

UTF-8 supports japanese characters.

and it works!

this is my PHP (and HTML) script :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>
</head>
<body>

<?php

$filename="japanese.txt";
//open file
$fp = fopen($filename,'r');

//loop through each line in the file
while($line=fgets($fp))
{
//output current text file line
print $line."<br>";
}
//close file handle
fclose($fp);

?>

</body>
</html>

I know it's a very simple script, for testing purposes only. It
displays the contents of the japanese text file line by line.

The key was to save all files in the same encoding (I used UTF-8) and
to specify the encoding / charset in the HTML header (<meta
http-equiv="Content-Type" content="text/html; charset=utf-8">)

Adding Text To Text Window With A Button
I have made an admin section of a site, What i want to do i have buttons under that have "BOLD" "center" and when clicked it adds <b></b> tags to the text area etc etc..

if the text area was called "message"

how would i going about coding the images / buttons to add the code?

PHP - Using Mail() And Unicode Text - Text Gets Disturbed
I have the following problem. On a website there's a (simple) feedback
form. This is used also by Polish visitors who (of course) type Polish
text using special characters.

However, when I receive the text in my mailbox, all special characters
have been turned into mess......

For example: "wspólprace" is turned into "współprace".

It seems PHP is handling the Unicode-8 strings quite well (when I
'echo' the strings on the site, I see the text correctly), until the
point that it is send by using mail().

Is this a server configuration issue? Or something else?

How can I get my text to remain in Unicode?

I have this problem both on my testserver (Apache 1.3.28, PHP 4.3.2 on
Windows XP) as on my providers server (Apache under Linux).

Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:

Parsing Text - Capture Text Between Two Tags
I want to have text in files, such as

{body}
{/body}

and then be able to open that file and grab all of the data inbetween those tags. I could open the file and go through it until I see the {body} tag and then store data until I reach {/body} but that is a bad way to do it.

Text Returned From DB Gets Cutoff When Placed In A Text Field
I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

For example:
$string_in_database = "John's car."

 -displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 -gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do.

Keep Text In Text Boxes After Form Is Rewritten
I'm trying to make a form that does the following:

(1) the user answers a question by typing in a text box
(2) a response is then written below the form, saying whether the answer is right or wrong and, perhaps making a comment of some kind
(3) the user's answer remains visible in the original text box

I've managed to write some code that does the first two things, but despite many attempts and much searching for code examples, I've failed to find a way of getting the answer to reappear in the text box when the page is rewritten.

This is my code:

Replacing Text For Use In A Text Area...
I have a PHP page that allows a user to preview an email and then send it
if(s)he is happy with it.

Otherwise, they can click on an edit button and edit the text of the
message. The text is then shown in a textarea element.

While in situation A (the preview), a bit of formatting is useful (e.g
<BR>), all of this formatting is a nuisance in the textarea.

Basically, I would like to do the following:
a. replace <BR> with a line break for the textarea
b. get rid of double spaces and tabs before the text is loaded in the
textarea
c. put the <BR>s back in when the user is finished with editing the message.

Is there a way to do this?

Text To Url
i have used the following function to convert text to url's where relevant (they need to have the http:// bit) PHP Code:

Add Text On Top Of PNG
Not sure if this is possible in PHP - every couple of weeks; i get a few png
files; which i th open in an image editor; add a text box with comments in
the top right corner; save the pngs and save them for later use by a php
script.

My question is there an automatic way so that a php script can do all this
image editing for me?

Arc Text With PHP
When I Google on "arc text", there are many references to graphics
software, and labelling software. But there are none for providing
this effect with a PHP script. I have looked at the documentation for
both imagemagick and GD, but I do not see anything there either.

Does anyone know of a way to do it?

No <br> In Text
I have a variable that includes a multi-line text but when I print it on the page I get all the text on the same line. Example:

"This is an
example of
how it could look."

When I print this I get: "This is an example of how it could look". I get the text from a mySQL database and when I look in phpMyAdmin evyrything looks fine so I don't think that it's saved in the wrong format or something in the database.

PHP TTF Text
Everytime i try to generate TTF text with the PHP inbuilt GD library and the TTF library (using my own external font however), it just returns a blank image with no text (and no error). Code:

Value In Text Box
how can i show the value in the input text box when i click edit from the previous form? so i can edit the value.

Get Text Between A And B?
I want to read out several strings from an HTML (text) file, like
everything between "<h2>" and "</h2>" to create a table-of-contents
(also, things other than tags).
I do have a function but it's slow, and sometimes doesn't finish for
larger files (600K, not much really!).
Now what would be a nice function to do this job? I suppose some regex
with preg_match_all?

It should have a parameter telling which occurrence of the string
should be used, e.g. the second, third and so on.

------------

Like:

function getTextBetween($allText, $textBefore, $textAfter, $offset = 0)
{
// ?
}

Then I could say:

$s = getTextBetween("<h2>foo</h2><p>Hello World</p><h2>bar</h2>",
"<h2>", "</h2>", 1);
echo $s; // ... would be "bar"

------------

Pdf To Text
I am looking for a way to convert PDF files into text content. I don't
care about layout or formatting, just the plain text that I can use to
search against in a database.

I've look into the pdftotext tool from:
http://www.foolabs.com/xpdf/download.html

However, when I use it via the command line, it works fine. If I issue
the same command via a system() call, there are major problems that
cause the server to crash. (Don't know why, there aren't any error
messages been generated anywhere.)

I am looking to use this when a PDF file is uploaded via a form and
store the text in a database for a search function.

Arrays And Text Box
I want to put the result of an array in a text box but instead of put the value it put Array[].

Here is the code:

$i=0;
while($row=mysql_fetch_row($result)){
for($j=0;$j<3;$j++){
$arreglo[$i][$j]=$row[$j];
}
$i++;
}


echo" <p align='left' size='><font color='#99CCFF' size='> Fecha: <input type='text' name='fech' value=$arreglo[0][1] size='></font>";

Chopping Up Text
I'm trying to chop a block of text into four equal sections:

$length = strlen($intro["homePage"]);

$break = round($length * .25);
$break2 = round($length * .50);
$break3 = round($length * .75);

$gDetails = substr($intro["intro"], 0, $break) . $img_1 . substr($intro["intro"], $break, $break2) . $img_2 . substr($intro["intro"], $break2, $break3) . $img_3 . substr($intro["intro"], $break3, $length);

echo $gDetails;


For some reason I'm getting strange break points, and a lot of repeating text. Can anyone help me out?

Displaying Text
I am just screwing around a little and trying to display some text to the screen via a link to the text in a mysql db.

Want To Split Text With The Tab
i want to split a text by using <tab> as a key but how i detect that is the <tab>
for example:
0807040009298 19862.090 16611.969 11980 M

i try to split to individual record but i cant.

Text To Smilies
Hey, it's me again, i have looked everywhere but i cant find something that tells me how to replace text strings with images (like smilies) this is my code:


Copyright © 2005-08 www.BigResource.com, All rights reserved