-1

I've been looking though google and stackflow for an answer for this and testing a few finds but I still can't get this working.

All of these end my link at a space. For example www.website.com/movies/movie
Where I'm trying to get it to read www.website.com/movies/movie with spaces here.mp4

$namehref = "movie/" . $dirArray[$index]. " download";

$DoStream = "<a href=" . $the_dir . ">Watch</a>";
$DoDownload = "<a href=" . $the_dir . ">Download</a>";

However this code does not remove the spaces???

$name = $dirArray[$index];
$movienameonly = substr($name, 0, -4);

example www.website.com/movies/movie with spaces here


So my questions are - Why does the first section of code remove the spaces and how do I correct it. In addition to spaces I also hit errors with 's as well.
example They're here.mp4

Joe Salmi
  • 79
  • 10

2 Answers2

0

To remove the spaces completely:

preg_replace("/\s/", "", $your_url);

To replace the spaces with %20 (best way):

preg_replace("/\s/", "%20", $your_url);

To replace spaces with + like url_encode($url) does:

preg_replace("/\s/", "+", $your_url);

To replace ' with %27:

preg_replace("/\s/", "%20", $your_url);

You get errors because spaces can't be inputted in the browser and converts the spaces to %20 and the apostrophe to %27

  • I can't figure out what is going on because it's still not working correctly. Your code does work, I was able to test it else wahere but I have something else going on here that I haven't found yet. When I right click on the link to view properties I see this, ​Watch Movie​​ However, right next to it I am using the same code to grab the movie name which prints correctly "30 minutes or less". Any ideas of why it would do this? – Joe Salmi Feb 15 '14 at 18:09
0

I found it:
$DoStream = "<a href=" . $the_dir . ">Watch</a>";

Should have been $DoStream = "<a href='$the_dir'>Watch</a>";

Joe Salmi
  • 79
  • 10