views:

53

answers:

3

Hi,

First off, I don't know much (quite nothing) about PHP. I'm more familiar with CSS.

I'm making use of Ben Ward script Tumblr2Wordpress (here's the script on GitHub) to export my Tumblr blog in XML (so I can import it in my Wordpress blog). This script reads tumblr's API, queries elements, do a bit of formatting and export the whole thing in HTML.

I need to customize it just a bit to fit my needs. For example in the following function I need the blockquote to become a specific class of blockquote:

function _doBlockQuotes_callback($matches) {  
    $bq = $matches[1];  
    # trim one level of quoting - trim whitespace-only lines  
    $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);  
    $bq = $this->runBlockGamut($bq);  # recurse  

    $bq = preg_replace('/^/m', "  ", $bq);
    # These leading spaces cause problem with <pre> content, 
    # so we need to fix that:
    $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', array(&$this, '_doBlockQuotes_callback2'), $bq);

    return "\n". $this->hashBlock("<blockquote>\n$bq\n</blockquote>")."\n\n";
}

At first, I thought it will be as simple as adding the class I need inside the blockquote HTML tag, like so <blockquote class="big"> But it breaks the code.

Is there a way I could add this HTML attribute as is in the PHP script? Or do I need to define the output of this <blockquote>somewhere else?

Thanks in advance for any tips!

P.

A: 

You need to escape the quote marks

 <blockquote class=\"big\">
Rocket Ronnie
Well, what can I say. Thanks for elusive for the re-formatting of my question... and to Rocket Ronnie for the answer he gave me while... I was still editing the question. That's fast.
Parneix
Your welcome, glad i could help
Rocket Ronnie
+2  A: 

Your guess was correct, but you need to escape the quotes with backslashes:

return "\n". $this->hashBlock("<blockquote class=\"big\">\n$bq\n</blockquote>")."\n\n";

Otherwise, PHP assumes that your string ends at the class=" quote.

elusive
Thank you Elusive, I really appreciate it. Can I ask what you did exactly to format the code in my question. I made use of the backticks but that was not enough. While you were editing it, I was trying to put backticks around every tags in the code I was quoting. I'll do better in the future.
Parneix
Code gets formatted (and syntax highlighted) by indenting it by four spaces. Backticks do not provide syntax highlighting. They are meant to be used for keywords or values.
elusive
+1  A: 

You can escape double quotes ".

"<blockquote class=\"big\">"

How ever, if you're going to use single quotes '. It's unnecessary.

'<blockquote class="big">'
Ruel
single quotes aren't appropriate in this case, because using them turns off variable interpolation, which is used for `$bq`
Javier
I'm just pointing out that escaping double quotes in single quotes isn't necessary.
Ruel