Textmate and PHP - having some trouble with the bundle - php

I've been using Textmate for Ruby/Python scripting for awhile and now have a need to hack on some PHP. I'm having some troubles with the bundle:
The code-highlighting doesn't support HTML...
When I type php + tab TM spits out:
?><?php>
instead of:
<?php ?>
Anyone know where I could possibly be going wrong? Thanks in advance...

Change your file type to HTML (even if you are editing a .php file!) would solve the problem.
The reason for this is documented at http://wiki.macromates.com/Troubleshooting/PHPSyntaxHighlight

No, the best way is to set language to "HTML" in the bottom status bar.
you can still have the file name ended with php

Related

PHP eval code and store the result into a variable

I have continued my voyage into creating a extremely simple template engine.
Because I wanted to add logic to my template I eventually got back to the point that I allowed PHP tags into my code which I enabled by evalling the code.
Maybe not the best solution but when looking at the WordPress templates I noticed that the idea itself may not be that bad.
But now there still is one small problem left.
And that is that I want to translate the generated code.
But it has been evalled already. Hence parsed.
I thought of solving this problem by using ob_get_contents().
But this brought one more question and in case of errors it shows a white screen. (memory usage etc.)
Plus it still did not take away the problem of eval that it parsed the contents when evalled.
In short the class logic is:
Loading template files
Adding the contents
Compiling the template
Eval the code (but unfortunately also displaying the code)
Translate the code so I can translate the code parsed by a PHP script
I would love something like:
$code = eval('?>'.$tpl.'<?php');
$code = translate($code);
WriteCache($code);
SetDocumentHeader();
echo $code;
Would anyone know how to achieve this?
Thanks in advance!
$code = eval($tpl);
Check this out.

Working with CodeKit and haml/PHP

in my latests projects I have use Rails. Now I have to do something in PHP (which I actually hate, or love too much Ruby syntax).
So now I am very used to work with Sass and haml, which I also love. So I bought CodeKit for doing things outside rails framework.
Wanted just to know if there is any option for use haml in PHP files, or PHP in haml files, and that the file compiles with CodeKit, even having PHP.
I know this is a very late reply, just found this question when searching myself.
In addition to Kevin's reply above:
You can automatically convert the html to php by simply setting the output path for that particular file, and then specifying the extension.
Right click your HAML or HTML
"Set output path..."
"Output filename and extension"
Change it from index.html or index.haml to index.php.
You can use the :plain filter to preserve the php, it does not parse the filtered text. This is useful when you need to keep multiple lines of php.
ex:
:plain
<?php foreach ($es as $e) {
echo $e;
} ?>
I have not heard about any haml/php color syntax for Sublime Text 2 yet.
There is another setting that can be useful for working with php : check the don't escape HTML character in the HAML config on Codekit : http://d.pr/i/4pmv
This will manage with that
%form#booking_log{:name => "booking_log", :method => "post", :action => "<?=$this->action('bookingGetLog')?>"}

Problem with prototype framework in cake php

This question is somewhat related to my previous question (not necessary to go through it)
link text
, although this one is more of an Ajax problem.
I tested my page in firebug and I am getting the following error
Event.Observe is not a function
Event.observe('form908983160', 'submit', function(event) { new Ajax.Updater('comments','/blog/posts/comments/add', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form908983160'), requestHeaders:['X-Update', 'comments']}) }, false);
I am using the prototype framework for developing my cake php application.
How should I fix this problem?
Guys, I really need your help in this one. I am really stuck at this one. [:(]
prototype.js has to be :
loaded in the page (verify it's not in 404, for instance)
loaded in the page before the execution of your script
Which generally means you need to include prototype.js first, and, only after that, you can include your scripts.
As a sidenote : you are not using any other JS Framework in that page, of course...
Remember that any Event.observers need to be used in global
Event.observe(window,'loaded',f);
// or
Event.observe(document,'dom:loaded',f)
otherwise they will not work.
For me it looks like there's problem with linking to Prototype. Open firebug and try to see the contents of your script files - if you see html, that means something went terribly wrong :-)

PHP: Where should I store the text for info & warning messages

I have a question concerning the design of my project's Code.
In most cases, it is important to separate content from code (HTML mixed with PHP in bigger apps=No good idea, etc.) but how should I handle things like the text of error messages?
Assuming this one message will be only used in one case/PHP file:
MessageBox( 'Something gone wrong, probably your fault' );
or
MessageBox( Lang::error_usersfault );
(Where Lang is a class located in some config file, full of consts)
If you have any experiences (I think every PHP programmer will come across something like this) with things like in the example above - What are they? How do you solve it?
What is the better solution?
May be you'll find php extension gettext useful?
MessageBox(_("Have a nice day"));
PHP Manual of Gettext::gettext

Convert HTML to PDF with HTML_ToPDF class (PHP)

In my project, I'm using HTML_ToPDF PHP class, which uses html2ps script to convert from HTML to PDF file.
Recently I upgraded my production server to Debian 5 (Lenny) and, after that, HTML_ToPDF is no longer working:
convert() method from HTML_ToPDF class is returning this error:
Error: there was a problem running the html2ps command. Error code returned: 127. setDebug() for more information.
And, the output from html2ps call is:
/usr/bin/perl: symbol lookup error: /usr/lib/perl5/auto/Compress/Zlib/Zlib.so: undefined symbol: Perl_Tstack_sp_ptr
Any help would be appreciated, thanks!
[Edited]
After some tests, I've found that the problem happens only with HTML containing images ( tags). When html2ps founds the first image it crashes. Converting HTML without images works fine. Any idea? Thanks!
Try this
apt-get install perl=5.8.8-7etch6 perl-base=5.8.8-7etch6 perl-modules=5.8.8-7etch6 debconf-i18n=1.5.11etch2 liblocale-gettext-perl=1.05-1 libtext-iconv-perl=1.4-3 libtext-wrapi18n-perl=0.06-5 libtext-charwidth-perl=0.04-4 html2ps=1.0b5-2 libapache2-mod-perl2=2.0.2-2.4 libcompress-zlib-perl=1.42-2 libfuse-perl=0.07-2+b2 libhtml-parser-perl=3.55-1 libhtml-tree-perl=3.19.01-2 libio-zlib-perl=1.04-1 libwww-perl=5.805-1 perlmagick=7:6.2.4.5.dfsg1-0.14 snmpd=5.2.3-7etch4 xhtml2ps mysql-client=5.0.32-7etch8 mysql-client-5.0=5.0.32-7etch8 libdbd-mysql-perl=3.0008-1 libdbi-perl=1.53-1etch1
http://www.deberias.com
This is an issue with the initial conversion from HTML to PS. Usually due to poorly written HTML.
Can you show some examples of what you are trying to convert?
To be honest I've found wkhtmltopdf to be far better than html2ps, even though it's at a fairly early stage of development.
I wrote a blog about it, but if you don't want to read that basically it uses KHTML/Webkit's rendering engine to render the page which is a bit more sensible than the usual approach of writing a complete HTML renderer.
The distributed binary worked just fine on my Debian server, and frankly the results are excellent.

Categories