Page 1 of 1

rawurlencode and sprintf

Posted: Mon Oct 17, 2005 8:05 am
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!

Posted: Mon Oct 17, 2005 8:20 am
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');

Posted: Mon Oct 17, 2005 8:24 am
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