简体   繁体   English

从PHP中生成的URL字符串中删除不需要的查询

[英]removing unneeded query from generated url string in php

I have the following string generating mp3 urls for a music player on my site. 我的网站上有以下字符串为音乐播放器生成mp3网址。

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

which results in /public/music_song/df/74/746b_2112.mp3?c=ec1e 这导致/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 我想从产生/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. 我已经研究了如何拆分url,但我还远不是php天才,因此我不知道要拆分或使用preg_replace还是要如何将其合并到现有字符串中。

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: 编辑:由于我还没有与SocialEngine合作,我想您需要做的是:

<?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 )); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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