Python Posted October 31, 2008 Share Posted October 31, 2008 Firstly, 'hi'. Im a noob when it comes to php, ive been able to tweak stuff buths about as far as if goes. Heres what im wanting to do.. I wanting to replace any spaces in the url with '+'. The file name will produce something like 'a random file' <td width="22%" class="alt1"><a href="http:www.website.com/{$file['name']}">Link to site:</a></td> So the outcome for that would be http:www.website.com/a random file and what im wanting is http:www.website.com/a+random+file Ive tried search all kind of topics that cover replacements and they all sound logical until it comes to putting it into practice just how exactly would i do that. Not sure if it matters but this code is going inside a vb template. Thanks to all that can help. (remember i'm a noob ;-) ) Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/ Share on other sites More sharing options...
bobbinsbro Posted October 31, 2008 Share Posted October 31, 2008 use: str_replace(" ", "+", $url); //where $url contains the url you want to edit Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678925 Share on other sites More sharing options...
Python Posted October 31, 2008 Author Share Posted October 31, 2008 I feel really thick and i'm really sorry but i dont understand how or where i would put that. Thankyou for helping. Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678930 Share on other sites More sharing options...
bobbinsbro Posted October 31, 2008 Share Posted October 31, 2008 i'll use your example: <td width="22%" class="alt1"> <a href="http:www.website.com/<?php echo str_replace(" ", "+", $file['name']) ?>">Link to site:</a> </td> Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678932 Share on other sites More sharing options...
Python Posted October 31, 2008 Author Share Posted October 31, 2008 Looked like it should have worked but i got this error. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Probably a vb issue but is there another way around this? Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678949 Share on other sites More sharing options...
bobbinsbro Posted October 31, 2008 Share Posted October 31, 2008 try adding a semi-colon ( after $file['name']). are the <?php ?> tags i used the only ones, or are they nested inside another pair (this would probably cause something unpleasant). Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678959 Share on other sites More sharing options...
Python Posted October 31, 2008 Author Share Posted October 31, 2008 Tried that but same error also tried removing the php tags still got error. Bet ur getting sick of me now. lol <td width="22%" class="alt1"> <a href="http:www.website.com/<echo str_replace(" ", "+", $file['name'])";>Link to site:</a> </td> <td width="22%" class="alt1"> <a href="http:www.website.com/<echo str_replace(" ", "+", $file['name']);">Link to site:</a> </td> <td width="22%" class="alt1"> <a href="http:www.website.com/<?php echo str_replace(" ", "+", $file['name']) ?>">Link to site:</a> </td> <td width="22%" class="alt1"> <a href="http:www.website.com/<?php echo str_replace(" ", "+", $file['name'] ?>">Link to site:</a> </td> <td width="22%" class="alt1"> <a href="http:www.website.com/<?php echo str_replace(" ", "+", $file['name']); ?>">Link to site:</a> </td> They are the ones ive tried. Below is the full error.. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/*********/user/htdocs/forum/includes/adminfunctions_template.php(3716) : eval()'d code on line 64 Not sure if that helps. Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678970 Share on other sites More sharing options...
bobbinsbro Posted October 31, 2008 Share Posted October 31, 2008 only thing i can think of is that it may be a VB error. i'm assuming that you have to declare a php block in some way to make VB ignore the php code. are you sure this declaration is set properly? Link to comment https://forums.phpfreaks.com/topic/130807-preg_replace/#findComment-678982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.