...

View Full Version : Error using echo



Democrazy
09-12-2011, 04:17 PM
Why do I get:

PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
... when using echo "Small - $data['sizes']";

mlseim
09-12-2011, 04:22 PM
The array is messing it up ...

Do this ... with brackets ...

echo "Small - {$data['sizes']}";

Or this ... appending string ...

echo "Small - ".$data['sizes'];

Or this .. changing array value to a variable ...

$size=$data['sizes'];
echo "Small - $size";


.

Democrazy
09-12-2011, 04:25 PM
Ah har yes, makes sense! I used the first one. Thank you for your help. :)

tangoforce
09-12-2011, 04:26 PM
Why do I get:

... when using echo "Small - $data['sizes']";

I've already replied to this in your other topic.

If you read the reply I left for you there you will see I recommended you look at the link in my signature about quotes and I also explained that you should not use single quotes for the array key inside double quotes.

tangoforce
09-12-2011, 04:27 PM
The array is messing it up ...

Do this ... with brackets ...

echo "Small - {$data['sizes']}";

Or this ... appending string ...

echo "Small - ".$data['sizes'];

Or this .. changing array value to a variable ...

$size=$data['sizes'];
echo "Small - $size";


.

Or the easier way - delete the single quotes:

echo "Small - $data[sizes]";

Democrazy
09-12-2011, 04:29 PM
Hmmm it does work, and tangoforce's suggestion is what I tried myself, but it won't work in the context I need it (which you will see why). I should of used this context in my OP. Appoligies, next time..

Anyway, I then tried to use your second suggestion mlseim, but it failed:

else {echo "Small - "}.$data['sizes'];

I also tried this:

else {echo "Small - ".$data['sizes']};

tangoforce
09-12-2011, 04:32 PM
I then tried to use the second suggestion, but it failed:

else {echo "Small - "}.$data['sizes'];

Not that you're listening to anything I say.. but here you go:

else {echo "Small - " .$data['sizes']};

Also unless you have a variable inside those double quotes swap them for single quotes.

READ THE QUOTES TOPIC IN MY SIGNATURE for the last time. You might actually learn something :thumbsup:

Democrazy
09-12-2011, 04:36 PM
I am new get over it, I can't remember everything in one go, and I have been listening to you. I even saved your lines from previous posts into a text file.

Democrazy
09-12-2011, 04:38 PM
else {echo "Small - " .$data['sizes']};


Does not work.

tangoforce
09-12-2011, 04:39 PM
But why open two topics about the same issue? - I had already explained this to you in the last one.

Democrazy
09-12-2011, 04:42 PM
Hey you know what! It is working. PHP was giving me some bizarre error about an error being on line 79, but the document only went upto line 78... so I performed undo to the last time the page was working and applied your code and it worked.

That is STRANGE!

Democrazy
09-12-2011, 04:42 PM
But why open two topics about the same issue? - I had already explained this to you in the last one.

Which other topic?

tangoforce
09-12-2011, 04:43 PM
Probably missing a ; somewhere or a } in the wrong place that you hadn't noticed. Happens to all of us.

Glad its working but now its time for you to brush up on your knowledge of quote marks before you get yourself into murkier water :thumbsup:

Democrazy
09-12-2011, 04:48 PM
Yeah, I am learning slowly.

If you were to tell me I'd understand basic PHP 2 weeks ago I would of laughed.

4 weeks ago I was convinced MySQL sucked and Python and flat-files was the answer to databases. LOL


Python is however, an AWESOME language and I have high respects for it.
Flat files are cool too, but for application configuration files like in Linux.

tangoforce
09-12-2011, 07:23 PM
Flat files are just wrong for a web based system IMO. Sure, it saves you having to learn to use mysql which always sounds daunting but flat files are not thread safe. That means two instances of your php script could access and read/write information to the same part of the file at the same time leading to data corruption. This is why using a thread safe database like mysql is superior to flat files.

Additionally with flat files you've got to write your own functions for finding data, updating it etc. Pain in the grass if you ask me.. I should know when I was writing apps in delphi rather than use a DB I was using ini files. 3 years later the application still isn't finished due to all of the file code needed.

Thenewphp
09-13-2011, 11:37 AM
am getting this error message: A non well formed numeric value encountered in C:\xampp\htdocs\index.php on line 13

With this :

<?php
$offset = 0;

if (isset($_POST['text'])&&isset($_POST['searchfor'])&&isset($_POST['replacewith'])) {
$text = $_POST['text'];
$search = $_POST['searchfor'];
$replace = $_POST['replacewith'];

$search_length = strlen($search);

if (!empty($text)&&!empty($search)&&!empty($replace)) {

while($strpos = strpos($text, $search, $offset)) {
echo $offset = $strpos + $search_length.'<br />';
}


}else {
echo 'Please fill in all fields.!';
}


}

?>


<form action="index.php" method="POST">
<textarea name="text" rows="6" cols="30"></textarea> <br /> <br />
Search for:<br />
<input type="text" name="searchfor"><br /> <br/>
Replace with:<br />
<input type="text" name="replacewith"><br /><br />
<input type="submit" value="Find and Replace">

</form>

mlseim
09-13-2011, 12:13 PM
This line:
echo $offset = $strpos + $search_length.'<br />';

Change to:
$offset = $strpos + $search_length;
echo '$offset<br />';

Thenewphp
09-13-2011, 01:42 PM
there was a little problem with yours too because finaly i found that its

echo $offset.'<br />';

But thank you you really help me man..

thank you

tangoforce
09-13-2011, 02:47 PM
what does not work?????

Nothing, it's been fixed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum