Jump to content

preg_replace


Python

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.