Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11504 > unrolled thread

str_replace ?

Started byrichard <noreply@example.com>
First post2013-10-20 20:48 -0400
Last post2013-10-23 17:03 -0700
Articles 11 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  str_replace ? richard <noreply@example.com> - 2013-10-20 20:48 -0400
    Re: str_replace ? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-10-20 21:02 -0400
      Re: str_replace ? richard <noreply@example.com> - 2013-10-20 21:55 -0400
        Re: str_replace ? David Robley <me@home.invalid> - 2013-10-21 12:41 +1030
      Re: str_replace ? richard <noreply@example.com> - 2013-10-21 09:16 -0400
    Re: str_replace ? Jerry Stuckle <jstucklex@attglobal.net> - 2013-10-20 21:06 -0400
    Re: str_replace ? Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-21 18:43 +0000
      Re: str_replace ? Norman Peelman <npeelman@cfl.rr.com> - 2013-10-21 19:10 -0400
    Re: str_replace ? Norman Peelman <npeelman@cfl.rr.com> - 2013-10-21 19:14 -0400
    Re: str_replace ? Tobiah <toby@tobiah.org> - 2013-10-23 10:04 -0700
      Re: str_replace ? Scott Johnson <noonehome@chalupasworld.com> - 2013-10-23 17:03 -0700

#11504 — str_replace ?

Fromrichard <noreply@example.com>
Date2013-10-20 20:48 -0400
Subjectstr_replace ?
Message-ID<izrf52ctugy3.3kvtllz245pf$.dlg@40tude.net>
In my database I am noting that none of the song names containing a single
quote are being written.
If I use str_replace, how exactly should I write it?

The php manual is not all that clear.
http://php.net/manual/en/function.str-replace.php

e.g.

Name of song is "I'm Sorry".

$song=str_replace($song,"'%");

[toc] | [next] | [standalone]


#11507

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2013-10-20 21:02 -0400
Message-ID<m2%8u.124879$VX2.53140@fx31.iad>
In reply to#11504
On Sunday 20 October 2013 20:48, in comp.lang.php, "richard"
<noreply@example.com> wrote:

> In my database I am noting that none of the song names containing a single
> quote are being written.
> If I use str_replace, how exactly should I write it?

By using mysql_real_escape_string()

http://ca1.php.net/manual/en/function.mysql-real-escape-string.php

See example #1, and modify for INSERT

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#11512

Fromrichard <noreply@example.com>
Date2013-10-20 21:55 -0400
Message-ID<1cg9644mwyvbx$.8m4jy9g0ple0.dlg@40tude.net>
In reply to#11507
On Sun, 20 Oct 2013 21:02:10 -0400, Lew Pitcher wrote:

> On Sunday 20 October 2013 20:48, in comp.lang.php, "richard"
> <noreply@example.com> wrote:
> 
>> In my database I am noting that none of the song names containing a single
>> quote are being written.
>> If I use str_replace, how exactly should I write it?
> 
> By using mysql_real_escape_string()
> 
> http://ca1.php.net/manual/en/function.mysql-real-escape-string.php
> 
> See example #1, and modify for INSERT

I don't quite follow the example.
What I have is this:

$played=$playme[$number][2];

mysql_query(
"INSERT INTO top20 (songs,name,hits) 
VALUES (' ".$song." ',' ".$played." ',1)
ON DUPLICATE KEY UPDATE hits=hits+1");

Assume that $played="I'm Sorry".

Please show me how and where to put the proper coding.

[toc] | [prev] | [next] | [standalone]


#11515

FromDavid Robley <me@home.invalid>
Date2013-10-21 12:41 +1030
Message-ID<l422e0$fg8$1@news.albasani.net>
In reply to#11512
richard wrote:

> On Sun, 20 Oct 2013 21:02:10 -0400, Lew Pitcher wrote:
> 
>> On Sunday 20 October 2013 20:48, in comp.lang.php, "richard"
>> <noreply@example.com> wrote:
>> 
>>> In my database I am noting that none of the song names containing a
>>> single quote are being written.
>>> If I use str_replace, how exactly should I write it?
>> 
>> By using mysql_real_escape_string()
>> 
>> http://ca1.php.net/manual/en/function.mysql-real-escape-string.php
>> 
>> See example #1, and modify for INSERT
> 
> I don't quite follow the example.
> What I have is this:
> 
$played = mysql_real_escape_string($playme[$number][2]);
> 
> mysql_query(
> "INSERT INTO top20 (songs,name,hits)
> VALUES (' ".$song." ',' ".$played." ',1)
> ON DUPLICATE KEY UPDATE hits=hits+1");
> 
> Assume that $played="I'm Sorry".
> 
> Please show me how and where to put the proper coding.

Use the above; this is simpler than trying to introduce you to the 
complexities of sprintf. You should use mysql_real_escape_string on any 
strings you send to mysql.
-- 
Cheers
David Robley

"I teach at a university," Tom professed.

[toc] | [prev] | [next] | [standalone]


#11531

Fromrichard <noreply@example.com>
Date2013-10-21 09:16 -0400
Message-ID<1a3nfdibw9pku.m4keavq8yw91$.dlg@40tude.net>
In reply to#11507
On Sun, 20 Oct 2013 21:02:10 -0400, Lew Pitcher wrote:

> On Sunday 20 October 2013 20:48, in comp.lang.php, "richard"
> <noreply@example.com> wrote:
> 
>> In my database I am noting that none of the song names containing a single
>> quote are being written.
>> If I use str_replace, how exactly should I write it?
> 
> By using mysql_real_escape_string()
> 
> http://ca1.php.net/manual/en/function.mysql-real-escape-string.php
> 
> See example #1, and modify for INSERT

BTW, it is working just fine thanks.

[toc] | [prev] | [next] | [standalone]


#11511

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-10-20 21:06 -0400
Message-ID<l41un2$6uc$6@dont-email.me>
In reply to#11504
On 10/20/2013 8:48 PM, richard wrote:
> In my database I am noting that none of the song names containing a single
> quote are being written.
> If I use str_replace, how exactly should I write it?
>
> The php manual is not all that clear.
> http://php.net/manual/en/function.str-replace.php
>
> e.g.
>
> Name of song is "I'm Sorry".
>
> $song=str_replace($song,"'%");
>

As you've been told may times before.  ALL strings used in accessing ANY 
SQL database need to be escaped.

You're not doing that.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#11538

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-10-21 18:43 +0000
Message-ID<l43sl2$3qu$5@dont-email.me>
In reply to#11504
On Sun, 20 Oct 2013 20:48:26 -0400, richard wrote:

> In my database I am noting that none of the song names containing a
> single quote are being written.

There are some functions that have been suggested to you time and time 
again over the years for making strings safe for use within urls, within 
sql databases, and within html.

The fact that you still ask these questions shows that you do not absorb 
the answers when they are given to you.

Therefore, there is now no point in providing the correct answers to 
these questions.

Instead, here is a suggestion. In future, before posting a question here, 
try entering into google (or any other search engine of your choice) the 
question you wish to ask, for example:

<url:http://lmgtfy.com/?q=how+do+i+use+php+strings+with+single+quotes+in
+sql+queries>

Wow, the 4th through 7th replies point to php online manual pages. I 
wonder if any of those might refer to the function needed. Best go read 
them and see.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#11539

FromNorman Peelman <npeelman@cfl.rr.com>
Date2013-10-21 19:10 -0400
Message-ID<l44c9r$66v$1@dont-email.me>
In reply to#11538
On 10/21/2013 02:43 PM, Denis McMahon wrote:
> On Sun, 20 Oct 2013 20:48:26 -0400, richard wrote:
>
>> In my database I am noting that none of the song names containing a
>> single quote are being written.
>
> There are some functions that have been suggested to you time and time
> again over the years for making strings safe for use within urls, within
> sql databases, and within html.
>
> The fact that you still ask these questions shows that you do not absorb
> the answers when they are given to you.
>
> Therefore, there is now no point in providing the correct answers to
> these questions.
>
> Instead, here is a suggestion. In future, before posting a question here,
> try entering into google (or any other search engine of your choice) the
> question you wish to ask, for example:
>
> <url:http://lmgtfy.com/?q=how+do+i+use+php+strings+with+single+quotes+in
> +sql+queries>
>
> Wow, the 4th through 7th replies point to php online manual pages. I
> wonder if any of those might refer to the function needed. Best go read
> them and see.
>

   What I've noticed is that whenever he is given something to learn, he 
disappears... he only want lines of code he can cut-n-paste.


-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#11540

FromNorman Peelman <npeelman@cfl.rr.com>
Date2013-10-21 19:14 -0400
Message-ID<l44ch4$73o$1@dont-email.me>
In reply to#11504
On 10/20/2013 08:48 PM, richard wrote:
> In my database I am noting that none of the song names containing a single
> quote are being written.
> If I use str_replace, how exactly should I write it?
>
> The php manual is not all that clear.
> http://php.net/manual/en/function.str-replace.php
>
> e.g.
>
> Name of song is "I'm Sorry".
>
> $song=str_replace($song,"'%");
>

   I really don't understand how you come up with that example. The 
manual is perfectly clear. But that's not your problem.

-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#11553

FromTobiah <toby@tobiah.org>
Date2013-10-23 10:04 -0700
Message-ID<wkT9u.111271$QZ6.42461@fx15.iad>
In reply to#11504
On 10/20/2013 05:48 PM, richard wrote:
> In my database I am noting that none of the song names containing a single
> quote are being written.
> If I use str_replace, how exactly should I write it?
>
> The php manual is not all that clear.
> http://php.net/manual/en/function.str-replace.php
>
> e.g.
>
> Name of song is "I'm Sorry".
>
> $song=str_replace($song,"'%");
>

You can also use parameter substitution with
mysqli.

[toc] | [prev] | [next] | [standalone]


#11565

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-10-23 17:03 -0700
Message-ID<l49o4h$2e3$1@dont-email.me>
In reply to#11553
On 10/23/2013 10:04 AM, Tobiah wrote:
> On 10/20/2013 05:48 PM, richard wrote:
>> In my database I am noting that none of the song names containing a
>> single
>> quote are being written.
>> If I use str_replace, how exactly should I write it?
>>
>> The php manual is not all that clear.
>> http://php.net/manual/en/function.str-replace.php
>>
>> e.g.
>>
>> Name of song is "I'm Sorry".
>>
>> $song=str_replace($song,"'%");
>>
>
> You can also use parameter substitution with
> mysqli.


mysqli is a dirty word to Richard.

Scotty

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web