Random PHP Question

Community Forums/General Help/Random PHP Question

(tu) ENAY(Posted 2011) [#1]
Been learning PHP today and ran into a seemingly easy but tricky to solve problem. All I want to do is read a file, read EVERYTHING.
But when I try reading it fails when encountering certain characters such as <>

I can understand these are reserved for HTML commands etc but there surely is a simply way of copying everything the file stream sees.

For example trying to read a file such as this:-

UP<DOWN>LEFT<RIGHT>


produces this:-

UPLEFT


I am probably just using the wrong command or missing a simple file parameter somewhere. Any tips? :)


Leon Brown(Posted 2011) [#2]
It looks to me that you are viewing this as HTML - in that case, the tags are being treated as HTML markup by the browser and are therefore being hidden. Instead go to view source in your browser to see the full content being output by PHP.


(tu) ENAY(Posted 2011) [#3]
Wow Leon, you were right. Looking at the source everything is there as intended, was just how I was interpreting the information. Thanks for that.
I learned something new today. :)


Leon Brown(Posted 2011) [#4]
I learnt that the hard way ;-).


simonh(Posted 2011) [#5]
Moving to General Help.


Zethrax(Posted 2011) [#6]
One genuine problem you may experience with PHP when writing to a file is if you find certain characters have a backslash added in front of them. This is caused by a piece of monumental stupidity called Magic Quotes.

http://en.wikipedia.org/wiki/Magic_quotes

If your server admins know their arm's bendy bit from their puckered orifice then they should have this turned off, though. I think you can also turn it off using local php.ini files or htaccess.


(tu) ENAY(Posted 2011) [#7]
OOh, the topic has moved. Thanks for all the posts guys. PHP is actually pretty simply, well if you have programmed in Blitz many of the commands are similiar.

One thing I am struggling with at the moment is very simply, changing a variable via the website.

All I want to do is get a text string to appear on the page in a box (I have that bit working) and then edit the string and click a button and it save the contents as a new variable.

Doing that seems very difficult though.

Last edited 2011


(tu) ENAY(Posted 2011) [#8]
OK, I still can't figure it out.

How do you simply change a variable? :)

Let's say I have a variable in php called $moo = 3
How do I change it to $moo = 4 ?
It's that simple.

I have experimented a lot with HTML and with the post functions and I can get something to change via user input but I can't get it to interact with php variables. Maybe I am missing something very simple.

When you change for example, your user details and the box comes up with your name, it appears in a text box, you edit the details and click commit and it saves it. How do I do this in php? It is driving me mad.

Any tips for a simple 'save one variable' in php code? :)


nrasool(Posted 2011) [#9]
Hi there

You have done it right. If we take a extremely simple example

<?php

$moo = 3;
echo $moo;

$moo = 4;
echo $moo;

?>


You will see the $moo variable has changed, so there is something else in your coding that has prevented the change.


When you change for example, your user details and the box comes up with your name, it appears in a text box, you edit the details and click commit and it saves it. How do I do this in php? It is driving me mad.



How are you saving the variable? Are you recording the changes in mysql database or just using variables in PHP?

Have a read through the following: http://www.homeandlearn.co.uk/php/php4p8.html

But in essence you would have something like

$username = $_POST['username'];


That will put the posted username textfield into a variable to which you can then use compare functions

Hope this helps you

Kind Regards


(tu) ENAY(Posted 2011) [#10]
Hi nrasool, yes that did help me. Thanks a lot! :)

Another friend also helped me and showed how to make this style of posting to another page encrypted.

I`ve written quite a good xml editor now. But php is very unforgiving, one tiny error and the browser shows nothing, nothing at all. Just white screen, very tough to debug things. Find myself having to comment out lines and then uncomment them one by one.

Last edited 2011


Perturbatio(Posted 2011) [#11]

I`ve written quite a good xml editor now. But php is very unforgiving, one tiny error and the browser shows nothing, nothing at all. Just white screen, very tough to debug things. Find myself having to comment out lines and then uncomment them one by one.


You need to enable error reporting either in your php ini file or in the .htaccess file (ONLY ENABLE IT WHILE DEVELOPING).