Say I'm using a snippet like
$phpfoo = "a\nb\nc";
var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be
escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
retrieved and displayed OK.)
What do you folks use in this kind of situation? Thanks, all.
AS 14 1386
On Apr 27, 7:35 am, ashore <3ash...@comcast.netwrote:
Say I'm using a snippet like
$phpfoo = "a\nb\nc";
var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be
escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
retrieved and displayed OK.)
What do you folks use in this kind of situation? Thanks, all.
If the $phpfoo string in PHP contains a new line then this is
something you solve with PHP before you print it into the HTML page.
Turn the new line character into somthing that will print as "\n" into
the page if you want the JavaScript to see the new line.
Peter
ashore wrote:
Say I'm using a snippet like
$phpfoo = "a\nb\nc";
var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be
escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
retrieved and displayed OK.)
PHP has addslashes e.g.
var jsfoo = "<?php echo addslashes($phpfoo); ?>";
that should help (although it is there in PHP to deal with escaping
strings for data base stuff).
--
Martin Honnen http://JavaScript.FAQTs.com/
ashore wrote:
Say I'm using a snippet like
$phpfoo = "a\nb\nc";
var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be
escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
retrieved and displayed OK.)
What do you folks use in this kind of situation? Thanks, all.
I imagine we would generate content that JavaScript could handle.
<script type="text/javascript">
var blah = '<?php print 'a\\nb\\nc'; ?>';
</script>
For example.
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Martin Honnen schrieb:
ashore wrote:
>Say I'm using a snippet like $phpfoo = "a\nb\nc"; var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be escaped somehow. (In my real case, $phpfoo came from MySQL, and it's retrieved and displayed OK.)
PHP has addslashes e.g.
var jsfoo = "<?php echo addslashes($phpfoo); ?>";
that should help (although it is there in PHP to deal with escaping
strings for data base stuff).
Actually, it's not JS that turns "\n" into a newline, it's PHP.
If single quotes (like below) don't make it go away, *then* it's time to
look for ways to escape it on the Javascript side; not before.
> <?php $phpfoo = 'a\nb\nc'; ?> var jsfoo = "<?php echo $phpfoo;?>";
--
cb
On 27.04.2007 16:35 ashore wrote:
Say I'm using a snippet like
$phpfoo = "a\nb\nc";
var jsfoo = "<?php echo $phpfoo;?>";
This errors out because JS sees the newline, and it needs to be
escaped somehow. (In my real case, $phpfoo came from MySQL, and it's
retrieved and displayed OK.)
What do you folks use in this kind of situation? Thanks, all.
AS
try
<?php echo addcslashes($phpfoo, "\0..\37");?>
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Martin Honnen wrote:
PHP has addslashes e.g.
var jsfoo = "<?php echo addslashes($phpfoo); ?>";
that should help
No, it does not help (as it does not esape \n), seems a regular
expression replacement is needed.
--
Martin Honnen http://JavaScript.FAQTs.com/
Martin Honnen wrote:
Martin Honnen wrote:
>PHP has addslashes e.g. var jsfoo = "<?php echo addslashes($phpfoo); ?>"; that should help
No, it does not help (as it does not esape \n), seems a regular
expression replacement is needed.
Huh? addslashes would yield a\\nb\\nc. That is effectively escaping
newlines is it not?
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Martin Honnen wrote:
PHP has addslashes e.g.
var jsfoo = "<?php echo addslashes($phpfoo); ?>";
In this case, addcslashes($phpfoo) would work better.
--
Toby A Inkster BSc (Hons) ARCS http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
-Lost wrote:
Huh? addslashes would yield a\\nb\\nc. That is effectively escaping
newlines is it not?
In the given example:
$phpfoo = "a\nb\nc";
No, it would not. addslashes() wouldn't do anything to that string.
--
Toby A Inkster BSc (Hons) ARCS http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Guys, the addslashes didn't work for me, tho I agree they shd! But
tell me why the following PHP didn't wrk:
$phpfoo = "\n\n\n";
print str_replace('\n' ,'ZZZZZZZZZZZZZ' ,$phpfoo);
AS
ashore wrote:
Guys, the addslashes didn't work for me, tho I agree they shd! But
tell me why the following PHP didn't wrk:
$phpfoo = "\n\n\n";
print str_replace('\n' ,'ZZZZZZZZZZZZZ' ,$phpfoo);
AS
Because of the single quote.
PHP process "\n", but does not process '\n';
Hendri
Hendri, you're right! I've been PHP'ing for years and didn't know
that. I knew in general that PHP wouldn't parse between sgl quotes,
but I didn't realize that included this situation. Thanks.
AS
ashore wrote:
print str_replace('\n' ,'ZZZZZZZZZZZZZ' ,$phpfoo);
Stop mucking around with str_replace. Just use addcslashes().
--
Toby A Inkster BSc (Hons) ARCS http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Yep, that works fine. But I need to show line breaks in the html. so
the str_replace() is still there.
Thanks for all the help here, folks. 'Preciated!
AS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wolfgang Keller |
last post by:
Hello,
Python seems to be used quite a lot for (the integration of) enterprise
applications. Just as an example, there are at least three (projects for
the implementation of) ERP systems in...
|
by: Dan |
last post by:
Hello all.
I am currently working on a project for several Hospitals. The
application is written in Java, and the database is either Oracle or
MySql, depending on the client. For a while now,...
|
by: Wayan |
last post by:
Geekcorps Volunteer - Systems Integration
Kenya, East Africa
Geekcorps http://www.geekcorps.org is in search of systems integration
professionals experienced in developing communication systems...
|
by: Magic1812 |
last post by:
Magic Software invites you to join us this coming Tuesday (January
13th, 2004) at 12:00 EDT / 17:00 GMT for
a FREE live Webinar:
Title: Accelerated Application Integration and Information...
|
by: Magic1812 |
last post by:
Magic Software invites you to join us this coming Tuesday (January
13th, 2004) at 12:00 EDT / 17:00 GMT for
a FREE live Webinar:
Title: Accelerated Application Integration and Information...
|
by: S Arnold |
last post by:
Date: June 24, 2004
Time: 4:00 PM - 5:00 PM (GMT +01:00)
Presenter: Richard Curtis
Description:
iBOLT, Magic's comprehensive EAI and BPM suite was recently described
by VP Strategic Services...
|
by: Stylus Studio |
last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That
is Modeled after the XQuery API for Java(TM) (XQJ)
BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies...
|
by: gb |
last post by:
We are in the process of upgrading part of a large system
to .NET, whilst the majority will remain ASP. Sharing
session state information will not be a problem at the
moment as it is trivial and...
|
by: Stylus Studio |
last post by:
Hey Everyone,
A new podcast entitled: Business-to-Business Data Integration in a SOA
World was just released by ZapThink.
The key speakers in the podcast are the following:
ZapThink...
|
by: YellowfinTeam |
last post by:
Marketplace: Yellowfin reporting 3.1 with BIRT Integration
Yellowfin is proud to announce the release of 3.1.
The major theme of this release is enhanced integration capability. We
have...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |