Hi all,
I'm looking for a way to scan a block of text and replace all the
double quotes (") with single quotes (').
I'm using PHP to pull text out of a mySQL table and then feed the text
into a javascript function called by onClick. The problem is that the
text may contain single or double quotes, which screws up the
javascript. I eliminated the single quote problem by running the text
through addslashes, but the double quotes are a problem.
Here is an example.
mySQL text:
the "father's" absorption, preoccupation and interest in the infant
after addslashes:
the \"father\'s\" absorption, preoccupation and interest in the infant
attempting to use in onClick:
onclick="printAnswer('the \"father\'s\ absorption, preoccupation and
interest in the infant')
Error in the javascript console:
Error: unterminated string literal
Source Code:
printAnswer('the \
Any tips or suggestions would be very welcome! 11 35809
Jakanapes wrote: Hi all,
I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes (').
Well, you could use str_replace('"',"'",$text) or use
htmlentities($text,ENT_QUOTES).
Example:
<?
$text = "This is a string with 'single quotes' and " . '"double quotes"
in it.';
echo $text."\n";
echo str_replace('"',"'",$text)."\n";
echo htmlentities($text,ENT_QUOTES);
?>
Yields:
php -q quotetest.php
This is a string with 'single quotes' and "double quotes" in it.
This is a string with 'single quotes' and 'double quotes' in it.
This is a string with 'single quotes' and "double
quotes" in it.
Ken
ah, that does it, thanks.
Could I use the same method to replace returns and newlines with <br>?
On 2005-01-19, Jakanapes <Ja*******@aol.com> wrote: Could I use the same method to replace returns and newlines with <br>?
You would normally use nl2br() for that.
--
Cheers,
- Jacob Atzen
Not quite, doesn't nl2br still leave the /n?
I'm looking to replace /r and /n in strings with <br>
On 2005-01-19, Jakanapes <Ja*******@aol.com> wrote: Not quite, doesn't nl2br still leave the /n? I'm looking to replace /r and /n in strings with <br>
Yes, it does. You can eliminate those with:
str_replace("\r\n", "<br/>",$string);
The above will only replace a consecutive \r\n.
--
Cheers,
- Jacob Atzen
Jacob Atzen wrote: str_replace("\r\n", "<br/>",$string);
That is better than nl2br in that it allows you to replace
newlines with '<BR>' instead of '<br />'.
--
Jock
John Dunlop wrote: Jacob Atzen wrote:
str_replace("\r\n", "<br/>",$string);
That is better than nl2br in that it allows you to replace newlines with '<BR>' instead of '<br />'.
Not true <http://in2.php.net/nl2br>
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
.oO(R. Rajesh Jeba Anbiah) John Dunlop wrote: Jacob Atzen wrote:
> str_replace("\r\n", "<br/>",$string);
That is better than nl2br in that it allows you to replace newlines with '<BR>' instead of '<br />'.
Not true <http://in2.php.net/nl2br>
nl2br() returns XHTML since PHP 4.0.5, which is not always what you
want.
Micha
Jacob Atzen wrote: On 2005-01-19, Jakanapes <Ja*******@aol.com> wrote: Not quite, doesn't nl2br still leave the /n? I'm looking to replace /r and /n in strings with <br>
Yes, it does. You can eliminate those with:
str_replace("\r\n", "<br/>",$string);
The above will only replace a consecutive \r\n.
both nl2br and str_replace have the disadvantage of not being MBCS (UTF-8
or other DBCS charsets) enabled.
ereg_replace would be the solution to use then ...
ereg_replace('"', "'", $string);
ereg_replace("'", '"', $string);
although it is likely much slower than both of these functions.
mark.
--
I am not an ANGRY man. Remove the rage from my email to reply.
R. Rajesh Jeba Anbiah wrote: John Dunlop wrote: Jacob Atzen wrote:
str_replace("\r\n", "<br/>",$string);
That is better than nl2br in that it allows you to replace newlines with '<BR>' instead of '<br />'.
Not true <http://in2.php.net/nl2br>
You've stumped me, phpSt.Rajesh.
--
Jock
John Dunlop wrote: R. Rajesh Jeba Anbiah wrote: John Dunlop wrote: Jacob Atzen wrote: > str_replace("\r\n", "<br/>",$string);
That is better than nl2br in that it allows you to replace newlines with '<BR>' instead of '<br />'.
Not true <http://in2.php.net/nl2br>
You've stumped me, phpSt.Rajesh.
Hey:-)
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian van den Broek |
last post by:
Hi all,
I'm posting partly so my problem and solution might be more easily
found by google, and partly out of mere curiosity.
I've just spent a frustrating bit of time figuring out why pydoc...
|
by: Kevin |
last post by:
I know this has probably been discussed many times before (I found
answers when I searched yesterday), but I still can't get it to
work...
I have an attribute @OID that can contain any...
|
by: Jason |
last post by:
I have several tables with quite a few fields and I'm getting errors when
trying to insert records with single quotes in the data like: name = John
O'Henry or a city name of O'Fallen
So I went...
|
by: gar |
last post by:
Hi,
I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code
text= Replace(text, """", "'"
This works fine (for normal double quotes).The problem...
|
by: Justin Fancy |
last post by:
Hi everyone,
I need to replace all instances of a double quote(") with two single
quotes('') in a text file. I already have some replacements of strings
going on, but I tried this one, but the...
|
by: bill |
last post by:
I am trying to write clean code but keep having trouble deciding
when to quote an array index and when not to.
sometimes when I quote an array index inside of double quotes I
get an error about...
|
by: joecolson |
last post by:
I've been trying to devise a JavaScript function that will take a GPS latitude or longitude coordinate expressed as degrees, minutes and seconds, and convert it to decimal degrees. Once the...
|
by: gimme_this_gimme_that |
last post by:
var a = 'what goes in here to get a single quote?';
|
by: Yearwood |
last post by:
Hi, I'm basically trying to import a CSV into an ACCESS database. Sample date is shown below:
"",10173,"Development Manager - Social Economy Sector","Trust Bank",10153,,"Lolalll Pudd","Meet the...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |