p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Replace in string, url


Message #1 by Jefferis Peterson <jefferis@p...> on Mon, 21 Oct 2002 11:32:41 -0400
Hi folks.  I'm working on a database of engagement rings which have 3 views
each.  The sql database has a link stored for the url for each picture and
thumbnail like this one:
<IMG src="/images/R-55B-02.jpg">

Since the image link for the front view will always be  an A, side view B
and Edge View C 
R-55A-02.jpg , R-55B-02.jpg , R-55C-02.jpg

I want to make a case insensitive replacement of the capital A with B or C
to call up the different images in the same table.

The images are called with this code:
<img src='<?php echo $row_viewall['thumbnail']; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0">

Where thumbnail is a relative URL "/thumbnail/R-55A-02.jpg"

So what I want to do is replace the A  with either the B or C and call up
those images in different cells in the row.

My code so far is balking. I'm  trying to use the ereg replace function.
> <img src='<?php $t1 = string ereg_replace ("A", "B",
> $row_viewall['thumbnail']);echo $row_viewall[$t1]; ?>'   >

Can someone help me figure out what I'm doing wrong, it won't parse. ?

Thanks,

Jeff

~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year

Message #2 by Jefferis Peterson <jefferis@p...> on Mon, 21 Oct 2002 11:37:04 -0400
On 10/21/02 11:32 AM, "Jefferis Peterson" <jefferis@p...>
wrote:

> 
> My code so far is balking. I'm  trying to use the ereg replace function.
>> <img src='<?php $t1 = string ereg_replace ("A", "B",
>> $row_viewall['thumbnail']);echo $row_viewall[$t1]; ?>'   >
> 
> Can someone help me figure out what I'm doing wrong, it won't parse. ?

I see I duplicated a query, but even removing it doesn't hel:

<img src='<?php $t1 = string ereg_replace ("A", "B",
$row_viewall['thumbnail']);
echo $t1; ?>' >
~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year

Message #3 by "KayKay-GG \(E-mail\)" <kaykay@g...> on Mon, 21 Oct 2002 23:14:09 +0530
Why don't you try strtr..
syntax:
strtr(stringtoedit,string_of_letters_to_replace,string_of_letters_to_replace
_with)...
so you are after something like...
strtr($row_viewall['thumbnail'],"A","B");

you might want to check that syntax up... :)
hope that's what you wanted :)
-K

>>>>-----Original Message-----
>>>>From: Jefferis Peterson [mailto:jefferis@p...]
>>>>Sent: 21 October 2002 21:07
>>>>To: beginning php
>>>>Subject: [beginning_php] Re: Replace in string, url
>>>>
>>>>
>>>>On 10/21/02 11:32 AM, "Jefferis Peterson"
>>>><jefferis@p...>
>>>>wrote:
>>>>
>>>>>
>>>>> My code so far is balking. I'm  trying to use the ereg
>>>>replace function.
>>>>>> <img src='<?php $t1 = string ereg_replace ("A", "B",
>>>>>> $row_viewall['thumbnail']);echo $row_viewall[$t1]; ?>'   >
>>>>>
>>>>> Can someone help me figure out what I'm doing wrong, it
>>>>won't parse. ?
>>>>
>>>>I see I duplicated a query, but even removing it doesn't hel:
>>>>
>>>><img src='<?php $t1 = string ereg_replace ("A", "B",
>>>>$row_viewall['thumbnail']);
>>>>echo $t1; ?>' >




  Return to Index