I can't see why this is wrong

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

I can't see why this is wrong

Post by akimm »

Well for now I'm going to post the code that I am having an error with, the one you suggested to format the textfile
This is the error is prints:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /nfs/cust/8/25/05/650528/web/clairictionary/clairictionary.php on line 590

Code: Select all

<?php
// write the info using the format needed so I don't have to edit it!
// id the variable to show how I want the $entry to look!

$entry = $name . #datasep# . $word . #datasep# . $definition . 

#entrysep;

$write_string = $entry
fwrite($fp, $write_string);

fclose($fp)

?>
If I'm not clear, my basic objective is to simply write to a file via a form ((already wrote it) this is just the error proned part of the code) and format the entrys to look like this

$name#datasep#$word#datasep#definition#entrysep#
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

You are trying to concatenate a string literal without quoting it, and the hash marks '#' have created comments in your code.

Code: Select all

<?php

// ASSUMES YOU CREATE A FILEPOINTER HERE WITH fopen()

// write the info using the format needed so I don't have to edit it!
// id the variable to show how I want the $entry to look!

$entry = $name . '#datasep#' . $word .' #datasep#' . $definition . '#entrysep';

fwrite($fp, $entry);

fclose($fp)

?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

ah yes

Post by akimm »

well double quotes jacked it up, so i tried no quotes at all, lol, thanks for clearing up a green hornes stupidity.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Re: ah yes

Post by bdlang »

akimm wrote:well double quotes jacked it up, so i tried no quotes at all, lol, thanks for clearing up a green hornes stupidity.
Hmm, double quotes should have worked just fine, as long as you used this method to seperate the variable name from the #other stuff#, e.g.

Code: Select all

$entry = "{$name}#datasep#{$word}#datasep#{$definition}#entrysep";
PHP Manual: Strings

Scroll down and have a look at the section marked 'Variable parsing'.
Post Reply