Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP Special Character


ghost's Avatar
0 0

Is there a simple way to print special characters in PHP? For example if I was to read a html file, and print it.. the output would be the actual contents of the HTML file.. instead I want to show what the code is.

Thanks in advance


ghost's Avatar
0 0

Thank you :)

Rather than opening a new thread I'll ask my next questoin here too..

When getting user input, from a form for example, and writing that to a file.. I get \' all the time rather than ' .. and the same with other special characters. I'm guessing there's a really simple way to avoid this that I've missed, is there?

Thanks yet again


ghost's Avatar
0 0

this is probably because you are hosting the php on some free host or something, and it is running the function addslashes() before displaying the text. might be some way to configure it in php.ini, but it would be easiest to run the text through stripslashes() before saving it.


ghost's Avatar
0 0

Thanks again.

Okay, both have worked well for me.

My only problem now is, that I'm printing the file with HTML characters stripped and for some reason, it's ignoring linebreaks. My solution to this before was to use <br> but because I need <br> and such to be printed I can't use that. Any ideas?


ghost's Avatar
0 0

x_5631 wrote: My only problem now is, that I'm printing the file with HTML characters stripped and for some reason, it's ignoring linebreaks. My solution to this before was to use <br> but because I need <br> and such to be printed I can't use that. Any ideas?

So, you're printing the contents of a file instead of the contents of a webpage. In that case, you're not working with HTML conventions… you're working with ASCII conventions. This should help:

http://us2.php.net/chr

Google will find you a good ASCII chart (every programmer should have one of these handy) but, for what you need, you currently only need the ASCII code for a line break: 13.


ghost's Avatar
0 0

Ok, thanks I'll give that a try.. although I'm not sure how I should use that because the file does conatin linebreaks already, it's just not outputting them.

I'll try readline I suppose, and append the (chr(13)) to the end of each line.

Now, if I get input from a form and I want to change it before it's submitted (using GET method) is there any way I can do that? I thought it might be possible in JavaScript. Example:

<form name="formone" action="mypage.php" method="GET"> <input type=text value="" name="textbox1"><br> <input type="submit" value="Submit"> </form>

and I want to change what's sent as the value "textbox1" when the user clicks the submit button.

Thanks again, and sorry for asking so many questions.


spyware's Avatar
Banned
0 0

If you control the form why don't you just change the $_GET using PHP? Otherwise, you're probably looking at a javascript solution.


ghost's Avatar
0 0

I need to change it before it's submitted to the PHP page.. for some reason it just doesn't load anything when there are certain things in the url because of the $_GET value, so I figured if I can convert it to something else before submitting it, then do the opposite on the PHP page where it's being used. So yeah I was aiming at using JavaScript but I wasn't sure if it could be done easily.


ghost's Avatar
0 0

Okay I fixed it using the following javascript:

{
	st = frm1.cont1.value;
	st = st.replace(/&#92;&quot;/g, &quot;SPC_2&quot;);
	st = st.replace(/&#92;&#39;/g, &quot;SPC_3&quot;);
	st = st.replace(/&#92;n/g, &quot;SPC_4&quot;);
	frm1.cont2.value = st;
	
	btn1 = document.getElementById(&quot;sbm&quot;);
	btn1.click();	
}```

and then on the PHP page that prints the file, I did the opposite replacements.

Thanks to everyone who helped for that help.