A small issue with PhP on Mac's text editor - php

I am editing my PhP files with Text Edit on my Mac.
The PhP files are source code I got from some tutorial.
The subtle issue I was able to notice is that the apostrophe ' on the source file is not the same apostrophe I type with my keyboard.
Also, when I try to type inside an existing string with the "source apostrophe" I notice the last letter goes outside the string and I am sure this is not a typo from my side.
When I put my keyboard apostrophe in the PhP file I get a 500 internal server error when requesting the PhP file.
If I just copy paste a "source apostrophe" I don't get the internal error.
Any idea what is going on here?
EDIT: As funny as it may be, I have put the 3 apostrophe here. The first one is from the source code(most left) the other two are from my keyboard.
' ' `

I just had a similar problem and discovered it was the Mac text editor automatically substituting Smart Quotes for single quotes. In TextEdit this can be disabled for the current document by unchecking the menu item Edit->Substitutions->Smart Quotes. Or uncheck Smart Quotes in the TextEdit Preferences->New Document->Options for all new documents.

Ok, I figured this out.
The apostrophe I was getting from my keyboard in Text Edit was UTF 8, it was 3 bytes long.
The "good" apostrophe was simply 27 hex.
I am now editing my PhP files with xCode instead of Text Edit.
I am guessing text edit does some rich text editing? Not sure.

This problem is related to MacOS System.
Solution:
System Preferences -> Keyboard -> Text Tab
for singled quotes: 'abc'
for doubled quotes: "abcd"
there, you can change the selected value.

Related

How to preserve line breaks in textarea?

I went through similar questions on this issue but couldn't find a solution.
I have a simple textarea in which text will be pasted or entered directly.
How do I preserve those line breaks?
Right now line breaks will just be ignored, but when I print_r($_POST) and inspect the output in the Chrome Developer Console it still has the original text breaks.
How can I display those when showing the submitted data?
Right now line breaks will just be ignored
No, it is still there. The key you miss is that what you enter goes as ASCII code LF (0xA) but this makes no effect in HTML unless the text is displayed as preformatted block (<pre> ... </pre>). If not, then line break is represented bytag so what you need to do if you want to display entered text is to convertLFs to(you can usenl2br()function to do that) or use` block.
You can use nl2br() function:
Inserts HTML line breaks before all newlines in a string
echo(nl2br($_POST));
More information at http://php.net/manual/en/function.nl2br.php.
As Marcin noted, use nl2br() when displaying your data as instructed in this answer: https://stackoverflow.com/a/6480671/6206601

using PHP include and symbol outputs

I'm building a website for a friend using Wordpress. There is one particular element he is going to need to update and he's not used to code so I have created a file that he can edit without getting involved in wordpress.
In wordpress I call this file using PHP include which works wonderfully until there are any £ symbols in the file. At this point the £ symbol gets replaced with a ? in a square thats been rotated 45 degrees.
I have looked on this site and found this, the problem being, that doesn't help me.
I have tried replacing the £ symbols for £ & £ both of which give the same output.
Anyone got any ideas?
EDIT: As requested;
<p class="menu_item">Americano - £2.00<br><span id="item_description">A double espresso stretched</span></p>
there are various lines like the one above in the file being called. I then call the file in wordpress using <?php include './wp-content/menu_content.txt'?> - I have tried calling it as a txt file, php and html.
I think this is not a problem with wordpress but rather with web server that tries to serve this site in some other encoding. Can you provide response/request headers and a raw html page heading?

codeigniter force_download leaving empty space

I'm having an issue, which seems like a bug, whereby if I download a CSV that I've created it seems to leave 12 empty spaces on the top of the file before filling in the content I want in there.
Is this just a general bug?
I'm using Codeigniter 2.1.3
Thanks Guys
I just had this same issue. When I looked through my code I was calling in a model that had a closing ?> tag, and for some weird reason, that created the extra space. Look to see if you have any closing php tags.
i had the issue too. But i solve it not related to closing ?>, but space in the beginning of php file. use tools such as winHex to open related php files, look if the file start with a space(in Hex it's 20), remove it, and the problem had solved.
sorry for my poor english.

htmlentities in PHP - differences between local and live

I edit certain pages of my website via textarea's and a common WYSIWYG editor. This editing frequently requires me to display HTML code by using <pre> tags.
Due to the nature of the textarea, I believe I'm required to use htmlentities in order to conserve HTML Entities such as < (which is translated to <), so here is what I did:
<textarea name="resume" class="ckeditor"><?php echo htmlentities($e['resume']) ?></textarea>
This works great locally, my syntax highlighter works great in the pre tags, the textarea doesn't convert the HTML Entities when being edited.
So I try hosting this project, but on live there is a problem, all double quotes are being displayed as \" , there is a slash before all double quotes in my text.
Is this something I should take up with my host? I don't understand how locally this issue isn't happening.
You have Magic Quotes enabled on the live site.
Look at the documentation for magic_quotes_gpc: http://php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
You can take it up with your host, but you can also disable it in a .htaccess file: http://php.net/manual/en/security.magicquotes.disabling.php

What's the trick to display a text from MySql/PHP back to its original HTML layout?

It still keeps the original text layout (I mean the spacing, offsets, new line, paragraphs) while the text fragment is stored in MySql ('text' type) field - I can tell when I peer into it in my DB browser (Adminer:)
but it gets lost when I output it from the DB: it becomes a single line string of my text characters. How can one restore it its original layout?
I've tried to reshape the text fragment using the PHP nl2br() function with some success:
it brought back the newline breaks, but the text words positioning is not kept, everything
shifts to the left.
Thanks in advance for a good idea.
If you've got multiple spaces and things like that. e.g. for code. Then trying using the pre tag.
http://htmldog.com/reference/htmltags/pre
http://reference.sitepoint.com/html/pre
The html_entity_decode() function converts HTML entities to characters.
The syntax is:
html_entity_decode(string, [quotestyle], [character-set]);
You can refer example2.

Categories