phpQuery behaving weird, changing HTML
I want to process a t开发者_开发知识库emplate with a Google plusone button in it through phpQuery and I run into the following problem:
require_once( "phpQuery.php" );
$p = phpQuery( "<g:plusone></g:plusone>" );
echo $p->html();
the expected output would be:
<g:plusone></g:plusone>
But instead the output of this is:
<plusone></plusone>
Which doesn't match up with what google is expecting, so the button doesn't work any more. How can I stop phpQuery from changing (fixing?) my code, or how can I work around this problem without changing the string from plusone to g:plusone once the processing is done? (that's a nasty workaround, plus, I run into more of these 'translation'-problems in phpQuery).
I had the same problem while including a google+ badge. I could force the code generator from google to generate code with a div container. I just had to tick the "html5 valid code" checkbox.
I've been looking all over for solutions for this problem, to no avail. I found a horrible workaround. I'm sure this is NOT the most elegant way to do this, but at least it fixes the problem.
Instead of the tags:
<g:plusone>...</g:plusone>
use:
<g__0058__plusone>...</g__0058__plusone>
Then simply str_replace the result before you're outputting:
echo str_replace("__0058__",":",$doc->html());
Basically in a tag where you would normally put a colon (:) you put 0058 instead. It's a very non-elegant solution, I realise that, but at least it's a workaround to this old problem.
精彩评论