Anybody know how to accomplish this?????

Discussion in 'PHP' started by boxer126, Feb 8, 2008.

  1. #1
    Hi everyone,

    I've solved one problem with embedding videos into blog posts, but it's created another. I use permalinks which contain the same name as the videos I want to post. So, to embed easily and dynamically with each page, I used the following command within my embed tag:

    <embed style="FILTER: xray" name="RAOCXplayer"
    src="<?php the_permalink()?>.wmv"
    </embed>

    Now, everything works great, except....the output is this:

    <embed style="FILTER: xray" name="RAOCXplayer"
    src="http://www.website.com/videos/this-is-my-video-name/.wmv"
    </embed>

    My question is, how can I strip that backslash (outlined in red) that occurs just before the file extension of .wmv without going into the "the_permalink()" function? There's gotta be a way. And I can't find where that function is located within WordPress. Any help would be appreciated.

    Thanks,
    boxer126
     
    boxer126, Feb 8, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    A couple ways, about about:

    src="<?php str_replace("/.wmv", ".wmv", the_permalink());?>.wmv"

    Or

    src="<?php stripslashes(the_permalink());?>.wmv"
     
    ToddMicheau, Feb 8, 2008 IP
    boxer126 likes this.
  3. boxer126

    boxer126 Well-Known Member

    Messages:
    878
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Thanks for the suggestions Todd. I couldn't get them to work however. I believe stripslashes strips all the slashes in the string, which would destroy the file path and with str_replace, the end of the file wasn't /.wmv, it was just the slash. I was trying to strip that slash and replace it with .wmv.

    Anyway, the answer turned out easier than expected. WordPress has an option that allows you to format the permalinks. I simply removed the slash in the options menu. Without the slash, the permalink function provides the correct url and I just appended .wmv to the end of it.

    Thanks again,
    boxer126
     
    boxer126, Feb 8, 2008 IP
  4. gwkg

    gwkg Peon

    Messages:
    143
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The string replace didn't work because .wmv isn't part of the_permalink()

    the_permalink() = http://www.website.com/videos/this-is-my-video-name/

    and the function is attempting to replace /.wmv with .wmv but there is no /.wmv in that string to replace

    for future reference, the easiest function to strip characters is substr()

    substr(the_permalink(), 0, -1) will remove the last character
     
    gwkg, Feb 8, 2008 IP
  5. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Oh, I don't know how I didn't see the ".wmv" after the php, sorry lol >.<
    But yea, like gwkg posted doing this would work:

    src="<?php substr(the_permalink(), 0, -1);?>.wmv"
     
    ToddMicheau, Feb 8, 2008 IP