简体   繁体   中英

removing unneeded query from generated url string in php

I have the following string generating mp3 urls for a music player on my site.

<?php echo $song->getTitle() ?>

which results in /public/music_song/df/74/746b_2112.mp3?c=ec1e

I would like to remove the query from the string resulting in /public/music_song/df/74/746b_2112.mp3

I've looked into how to split the url, but I'm nowhere near being a php genius just yet so I dont know weather to split or use preg_replace or how the heck to incorporate it into my existing string.

I have to get rid of these queries, they are unneeded and crashing my databases on a daily basis.

list($keep) = explode('?', '/public/music_song/df/74/746b_2112.mp3?c=ec1e');
$parsedInput = parse_url('/public/music_song/df/74/746b_2112.mp3?c=ec1e');
echo $parsedInput['path'];
// Results in /public/music_song/df/74/746b_2112.mp3

Edit: Since I havent worked with SocialEngine, Im guessing that what you need to do is:

<?php $parsed = parse_url($song->getFilePath());
      echo $this->htmlLink($parsed['path'], 
                           $this->string()->truncate($song->getTitle(), 50), 
                           array('class' => 'music_player_tracks_url', 
                                 'type' => 'audio', 
                                 'rel' => $song->song_id )); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM