Web Development Thread, Concatenate in PHP in Coding and Web Development; I have an internal web application I designed where a teacher adds a title and web url to a form. ...
13th November 2008, 03:57 PM #1
Concatenate in PHP
I have an internal web application I designed where a teacher adds a title and web url to a form. This is then stored in a database. The web url is also stored in a text file.
I want the database to store the full address i.e.
But I want the text file to only store:
RM - Exciting Learning
Can anybody help me concatenate this? This is the code I use to write the url to the text file at the minute:
EDIT: I don't think the term is concatenate but I'm sure you know what I mean...
//This adds the address submitted to a text file
//ready for the proxy server to use
$myFile = "whitelist.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_POST['txtAddress'];
Last edited by Hightower; 13th November 2008 at 04:00 PM.
Reason: Because I'm an idiot.
13th November 2008, 04:12 PM #2
concatenate is when you want to join strings together...
u mean u just want the http:// domain / ?
if you split the string on on the slashes, u know u want everything before and including the 3rd slash
13th November 2008, 04:28 PM #3
Sorted it - I was looking for a kind of TRIM so I only have the domain name.
PHP: parse_url - Manual - This did the job.
13th November 2008, 04:29 PM #4
Another problem I'm getting though based on the code above, is my text file has multiple lines in between each entry when I don't want any. Just want one carriage return like this:
Not like this (which is how its working at the min)
It doesnt hurt - the text file just looks messy. Any ideas?
13th November 2008, 04:54 PM #5
I think the problem is the '\r' escape code. I think it's an additional, not needed carriage return which is causing the problem. '\n' on it's own should work.
Originally Posted by Hightower
I'd rewrite thus
$stringData = $_POST['txtAddress']."\n";
$stringData = "\n".$_POST['txtAddress'];
13th November 2008, 05:22 PM #6
wont trim sort of thing fix that too?
Originally Posted by Hightower
13th November 2008, 05:29 PM #7
Thanks but didn't work - I've just added to address' and it appeared like this in the text file:
Originally Posted by tmcd35
13th November 2008, 06:21 PM #8
instead of \r\n
14th November 2008, 09:54 AM #9
Now I'm getting this with Toms answer....
(The square brackets represent a rectangle character in a text file.)
14th November 2008, 09:58 AM #10
What web server and platform are you running, and what application and platform are you reading the file on?
14th November 2008, 10:03 AM #11
Try replacing '\n' with '\r'
Alwaysed used '\n' for new line before and never had a problem. I'm guessing '\r' is a carriage return code. never used it before. I think your original problem was becaude you where using both, I think needed for Windows .txt files. On that logic. If '\n' doesn't work, try '\r' on it's own.
14th November 2008, 11:32 AM #12
Last edited by Hightower; 14th November 2008 at 11:34 AM.
Reason: Dupe post
14th November 2008, 11:33 AM #13
This is what I've tried: (note  means a square in a text file)
The last one is close but I still get those stupid square characters that I don't want.
14th November 2008, 12:43 PM #14
I would suggest that there may be trailing characters on your input - worth checking.
Seems a lot of your probs could be windows/unix related - remember the two OS's terminate lines differently. If this file si not meant to be human readable, of course, it does not matter, you could put nulls or tabs, or anything between em.
14th November 2008, 12:56 PM #15
The file needs a line break for the server to read each line properly. It kind of needs to be readable in case it needs to be edited.
When you say trailing characters do you mean something like the web address might look like ____www.rm.com____ (where _ is a space)?
Should I run the trim function on this?
By Cravon in forum Coding
Last Post: 20th November 2007, 06:05 PM
By browolf in forum Web Development
Last Post: 23rd May 2007, 01:06 PM
By Gatt in forum Web Development
Last Post: 14th November 2006, 10:01 PM
By beeswax in forum Windows
Last Post: 14th October 2005, 05:51 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)