I'm having a little trouble running a urlencode on the following string within the str_replace function. The String: $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); Code (markup): Basically (not correct code - but what I want to do is this: $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', urlencode($bbcode_tpl['url'])); Code (markup): What's the correct syntax for that? Really appreciate any help.
I guess that: $bbcode_tpl['url'] = 'http://blabla.com/bla.php?blabla=true' PHP: I think that you want to make this: $bbcode_tpl['url1'] = urlencode('http://blabla.com/') PHP: Am I right? If not, please tell us what exactly you want $bbcode_tpl['url1'] to look like, so we can help you.
Thank you for your reply. No, $bbcode_tpl['url'] is a long string and what we are doing it only replacing part of the string, however with the replaced part I want to URLENCODE it whilst doing the replace. Here is the full code so that it may help: // We do URLs in several different ways.. $bbcode_tpl['url'] = 'str_replace("\\\'","\'","'.str_replace('{NOFOLLOW}', '".add_nofollow(str_replace("\\\'","\'","\\1"))."', addslashes($bbcode_tpl['url'])).'")'; $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']); $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']); $bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']); $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']); $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']); Code (markup):
Well, I guess that URL contains characters which can be affected by urlencode(). So you should first urlencode the URL and then use this: $bbcode_tpl['url1'] = str_replace("$urlencodedURL", '\\1', urlencode($bbcode_tpl['url'])); PHP:
Thanks for the reply; we are getting this: You see... with this string: $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); Code (markup): {URL} is being replaced with "part" \\1 from the $bbcode_tpl['url'] - basically what I need to do is urlencode only the part that's replacing {URL}. Complex scenario and I'm not that sharp at coding. Any help or suggestions will be great!
Ok, in simpler terms, how would I add an urlencode here: $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); Code (markup): For example, the correct syntax for doing something like this: $bbcode_tpl['url1'] = str_replace('{URL}', 'urlencode(\\1)', $bbcode_tpl['url']); Code (markup):
This {URL} has be part of this $bbcode_tpl['url'] and when it does match, this {URL} will be replace by this \\1 So without examples of the two urls its going to be impossible to advise.... Start at the beginning and explain exactly what your trying to do with the urls, you might not need urlencode() or you should be using urldecode() first, preg_replace() is always an option too.
Is it not possible to urlencode it while it is being replaced? In the same action? For example, the line before does some strange things all in one go: $bbcode_tpl['url'] = 'str_replace("\\\'","\'","'.str_replace('{NOFOLLOW}', '".add_nofollow(str_replace("\\\'","\'","\\1"))."', addslashes($bbcode_tpl['url'])).'")'; Code (markup):