penders

msg:4344279 | 11:05 pm on Jul 26, 2011 (gmt 0) |
PHP's variable parsing [am.php.net] ability in double quoted and HEREDOC strings (as you are using above) unfortunately does not extend to parsing all PHP syntax, just variables. So you would need to assign your statement to a variable first and use that...
$filename = basename($item->guid,'.xml'); echo <<<END <img src="images/ProductCovers/$filename.jpg" /> END; basename() [am.php.net] would seem to be a better suited function in your case, than substr().
|
doubleJ

msg:4344287 | 11:37 pm on Jul 26, 2011 (gmt 0) |
I'll have to look at basename(). I haven't seen that, before. It's entirely possible that I could be more efficient. Hehehe... JJ
|
doubleJ

msg:4344488 | 2:04 pm on Jul 27, 2011 (gmt 0) |
That worked like a charm and I like basename(). That will help a lot. Thanks... JJ
|
doubleJ

msg:4344522 | 3:44 pm on Jul 27, 2011 (gmt 0) |
How do you .PHP_EOL with HEREDOC? This works...
echo <<<END <div>stuff</div>\n END;
And this works...
echo "<div>stuff</div>".PHP_EOL;
But this doesn't...
echo <<<END <div>stuff</div>.PHP_EOL END;
And neither does this...
echo <<<END <div>stuff</div> END.PHP_EOL;
JJ
|
penders

msg:4344549 | 4:33 pm on Jul 27, 2011 (gmt 0) |
I don't think you can include global constants with HEREDOC syntax. It will be treated as a literal string eg. "PHP_EOL". It's always looking for a '$' as the first char, as for variables. You need to assign it to a variable IMO. However, be careful....
echo <<<END one\n two\n three\n END; Lines 'one' and 'two' automatically have newlines appended to the end of the lines, as they appear in the source code. So the first two lines will have 2 newlines appended to the end. ie. Double spaced.
|
doubleJ

msg:4344607 | 5:58 pm on Jul 27, 2011 (gmt 0) |
Yes, I've seen that, already. Thanks for the input. I keep looking at the source to make sure it's the way I want. I looked at the source for google's website and I realized how bad automated code could look. Hehehe... JJ
|
penders

msg:4344668 | 8:07 pm on Jul 27, 2011 (gmt 0) |
You should also perhaps look at sprintf() [am.php.net] which you can combine with the HEREDOC syntax.
|
penders

msg:4348418 | 9:25 pm on Aug 5, 2011 (gmt 0) |
This has just cropped up again in something I'm working on.... In your original post you are attempting to execute a global function as part of a variable parsed string. My suggestion was to assign this to a variable and use that instead. Whilst this is still correct, you can actually call functions using complex syntax (in PHP 5), but the result is probably not what you'd expect. The output of that function is treated as a variable and that variable is parsed into the resulting string (like variable variables [am.php.net]), which is of limited use IMO. However, you can call methods of class instances and these are parsed as expected. eg. <?php class DummyClass { public function exampleMethod() { return base64_decode('SGVsbG8gV29ybGQ='); } } $instance = new DummyClass(); // Outputs "...: Hello World" echo "Class instance method output: {$instance->exampleMethod()}"; ?> |
|
|
doubleJ

msg:4348611 | 2:18 pm on Aug 6, 2011 (gmt 0) |
Hehehe... That's some nify code. That might be a little out of my pay grade. I did understand the "Hello World" part. JJ
|
|