Viewing Topic: str_replace
problem |
sm0ke |
Subject: "str_replace
problem"
Posted: @ 1:13 am on Oct 01 2006 |
|
|
 Member #: 168 Rank: user - (83) Since: 06/05/06 Posts: 34 From: Manchester - UK
|
I've got a
problem with a
str_replace()
function for a
site I'm
working on, Its
probably
something and
nothing but
extra eyes are
appreciated.
Im replacing
spaces with
underscores,
and then &
operatoers with
the + symbol
using the
following code:
Code:
$query =
"SELECT *
FROM table
WHERE t =
'stored' AND c
= '1' ORDER BY
i DESC LIMIT
0,6";
$r =
mysql_query($qu
ery) or die
("Error in
query:
$query" .
mysql_error());
// if records
present
if
(mysql_num_rows
($r) > 0)
{
while($mx =
mysql_fetch_obj
ect($r))
{
$title =
str_replace('
', '_',
$mx->l);
$title =
str_replace('&a
mp;', '+',
$title);
Which
successfully
changes the
characters as
above.
To change them
back again I'm
using the
following code:
Code:
$l =
str_replace('_'
, ' ', $l);
$l =
str_replace('+'
, '&',
$l);
$sql =
"SELECT *
FROM table
WHERE l =
'$l'";
$provide =
mysql_query($sq
l) or die
("Error in
query:
$sql" .
mysql_error());
Any title which
does not
contain the
& sign
resolves
correctly with
but the title
containing
"&&quo
t; do not, the
symbol is
rewritten in
the url but
does not appear
to convert
back.
Any help
Cheers Edited at 01:20:46 am on 10/01/06
Just because I
dont care,
doesnt mean I
dont
understand. |
| Viewed: 18,230 Times | |  |
bs0d |
Subject: "re: str_replace
problem"
Posted: @ 2:49 am on Oct 01 2006
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
I think i have
your answer
when you want
to replace more
than one item,
use array()...
like this:
Code:
$l =
str_replace(arr
ay('+',
'&'),
$l);
//and
$title =
str_replace(arr
ay('&',
'+'),
$title);
|
Viewed: 18,221 Times | |  |
ki |
Subject: "re: str_replace
problem"
Posted: @ 3:02 am on Oct 01 2006
|
|
|
 Member #: 204 Rank: user - (50) Since: 09/16/06 Posts: 53 From: Florida
|
uh, try
this
Code:
$da =
array('+');
$l =
str_replace($da
,'&',$l)
by the way what
font this site
use?
Edited at 03:12:03 am on 10/01/06
|
Viewed: 18,218 Times | |  |
bs0d |
Subject: "re: str_replace
problem"
Posted: @ 3:20 am on Oct 01 2006
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
This site or
Smoke's? I
use:
font-family:
Verdana,
Tahoma;
|
Viewed: 18,211 Times | |  |
ki |
Subject: "re: str_replace
problem"
Posted: @ 4:18 am on Oct 01 2006
|
|
|
 Member #: 204 Rank: user - (50) Since: 09/16/06 Posts: 53 From: Florida
|
bs0d
said...
<
i>
This site or
Smoke's? I
use:
font-family:
Verdana,
Tahoma;
I did mean this
site and, I use
the same thing

|
Viewed: 18,209 Times | |  |
sm0ke |
Subject: "re: str_replace
problem"
Posted: @ 11:11 am on Oct 01 2006
|
|
|
 Member #: 168 Rank: user - (83) Since: 06/05/06 Posts: 34 From: Manchester - UK
|
Ah
My bad im
afraid. Both
ways posted
above and the
way I was
working it all
worked fine,
but I was
trying to pass
operators like
"+"
and
"&&q
uot; via a url,
making the site
think that
halfway thru a
title it had a
new variable to
process and
therefore not
matching a full
title so
returning
NULL.
As opposed to
writing a
function to
change the
dynamic url as
well as the
rewritten url,
I've changed
all 35 whole
records
containing
"&&q
uot; to either
"and&quo
t; or
"n"
and will advise
the site admin
to do so.
I'll probably
fix it up on
the next
release of
their site and
post a solution
here.
Thanks for the
help
Just because I
dont care,
doesnt mean I
dont
understand. |
| Viewed: 18,202 Times | |  |
bs0d |
Subject: "re: str_replace
problem"
Posted: @ 2:59 pm on Oct 01 2006
|
|
|
 Member #: 1 Rank: Admin. - (1,510) Since: 02/06/05 Posts: 604 From: USA
|
Have you tried
& for
"&&q
uot; and
+ for
"+"
? put the codes
in your url and
they will show
up as & and
+
|
Viewed: 18,199 Times | |  |
sm0ke |
Subject: "re: str_replace
problem"
Posted: @ 4:28 pm on Oct 01 2006
|
|
|
 Member #: 168 Rank: user - (83) Since: 06/05/06 Posts: 34 From: Manchester - UK
|
Tried that but
it was still
the same.
I think its due
to the php
script grabbing
a url like -
detail.php?var=
this &
that
so the browser
is reading it
as
detail.php?var=
this &
that=(no var)
and only
matches the
part prior to
& in the
database, as
replacing the
actual titles
on pages works
regardless of
how the
str_replace()
is
constructed.
cheers
Just because I
dont care,
doesnt mean I
dont
understand. |
| Viewed: 18,194 Times | |  |
misterhaan |
Subject: "re: str_replace
problem"
Posted: @ 2:38 pm on Oct 02 2006
|
|
|
 Member #: 5 Rank: Contributor - (214) Since: 02/11/05 Posts: 149 From: chair
|
you need to url
encode them to
use them as
data -- &
becomes %26 and
+ becomes %2B
please note
that the above
post is likely
made up in its
entirety. |
Viewed: 18,182 Times | |  |
sm0ke |
Subject: "re: str_replace
problem"
Posted: @ 7:30 pm on Nov 18 2006
|
|
|
 Member #: 168 Rank: user - (83) Since: 06/05/06 Posts: 34 From: Manchester - UK
|
Cheers
misterhaan
I'll try that
out in the next
rewrite and let
you know how it
goes.
sm0ke
Just because I
dont care,
doesnt mean I
dont
understand. |
| Viewed: 17,976 Times | |  |
Viewing Page: 1 of 1 |