rawurlencode and sprintf

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

rawurlencode and sprintf

Post by shiznatix »

ok my boss insists on using sprintf for this part. here is what i got

Code: Select all

sprintf ('<li><a %s href="index.php?id=%s&p='.$name.'">%s</a>'
problem is that $name is going to have ' & ' without the quotes in it somtimes. that blows up things. i tried using rawurlencode($name) and it returns the error, too few arguments for sprintf and im like die! then i tried just

Code: Select all

str_replace(' &', 'AAA', $name);
//then back again respectivly
but for some reason or whatever it goes from WORD & OTHER to WORDamp; OTHER and im like WTF! then i did replace on the amp; and then back respectivly but this is all turning out to give me no results. any ideas? this makes no sence to me why its going crazy

edit:

when i don't do any str_replaces then the url is WORD%20&%20OTHER ok well no problem just str_replace the %20's to spaces right? well when i try that it just leaves me with the 1st word and deletes the rest of it so it just turns to WORD. WTF!
Last edited by shiznatix on Mon Oct 17, 2005 8:21 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rawurlencode() is the way to go with it.. however, you aren't using sprintf() correctly it appears...

Code: Select all

$string = sprintf('<li><a %s href="index.php?id=%s&p=%s">%s</a>','someattrs','someString',rawurlencode($name),'some other string');
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ahhh yes ok now that works thanks. ya i had ommited some of the sprintf stuff becuase the rest of the line goes on and on and on. thanks
Post Reply