Jump to content

Recommended Posts

Hi i want to do this but i dunno where to start havent really looked into regex.. so maybe some can help me out..

 

Lets Say i post a link like this from a form:

http://yourdomain.com/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3

 

what i need to getin return is this:

 

Artist: Dj Mtamerr

Track: Lessons In Love

 

AND IN Cases like:

 

http://yourdomain.com/Dj_Mtamerr_Ft_Dj_Sdoko_-_Lost_In_Time_-[32kbs]-_[YourDomain.com].mp3

 

Artist: Dj Mtamerr Ft. Dj Sdoko

Track: Lessons In Love

 

to be printed out

 

dunno if its possible bu if it is some1 please show me the way :) ty.

Link to comment
https://forums.phpfreaks.com/topic/103003-extract-text-from-link/
Share on other sites

<?php
$url = 'http://yourdomain.com/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3';

list($artist, $track) = explode('-', parse_url($url, PHP_URL_PATH));

$artist = str_replace('_', ' ', ltrim($artist, '/'));
$track = str_replace('_', ' ', $track);
?>

 

Try that. It isn't tested.

 

Edit: Just tested it. It does work. You might want to run both $artist and $track through trim() to remove the spaces at the start and end of the string.

Thanks for both  post especially Daniel0 your code worked wonders :)

 

EDIT:

 

well just tested my self all is good until i use a link like:

http://yourdomain.com/files/1186885_f5plf/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3

 

now it prints

 

Artist:files/1186885 f5plf/Dj Mtamerr

Track: Lessons In Love

 

is there a way to exclude any text before the "/"

 

anyways i thnk i need a new phpbook any suggestions?

Ah, well... I just assumed the domain would look sort of like the one you originally posted.

 

Try this instead:

<?php
$url = 'http://yourdomain.com/files/1186885_f5plf/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3';

list($artist, $track) = explode('-', strrchr($url, '/'));

$artist = trim(str_replace('_', ' ', ltrim($artist, '/')));
$track = trim(str_replace('_', ' ', $track));
?>

can u please look at this and tell me why the data is not getting printed?

 

im posting it from a form the artist and the track strings are blank the rest of the data posts ???

<?php

for($i=0;$i<$forms;$i++){

$url = '$link[$i]';

list($artist, $track) = explode('-', strrchr($url, '/'));

$artist = str_replace('_', ' ', ltrim($artist, '/'));
$track = str_replace('_', ' ', $track);






echo "<table>


<tr><td class=\"lefts\" style=\"text-align: left;\">
Name: <b>$track[$i]</b>
</td><td class=\"right\"></tr>
<tr><td class=\"lefts\" style=\"text-align: left;\">
Artist: <b>$artist[$i]</b>
</td><td class=\"right\"></tr>
<tr><td class=\"lefts\" style=\"text-align: left;\">
Link: <b>$link[$i]</b>
</td><td class=\"right\"></tr>
<tr><td class=\"lefts\" style=\"text-align: left;\">
Cat: <b>$cat[$i]</b>
</td><td class=\"right\"></tr>
<tr><td class=\"lefts\" style=\"text-align: left;\">
Alpha: <b>$alpha[$i]</b
</td><td class=\"right\"></tr>
</table>
has been added successfully";

}
}
?>

done that but the returned text is still blank

 

Name: 	
Artist: 	
Link: http://yourdomain.com/files/1186885_f5plf/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3 	
Cat: rnb 	
Alpha: d	
has been added successfully
Name: 	
Artist: 	
Link: http://yourdomain.com/files/1186885_f5plf/Dj_Mtamerr_-_Lessons_In_Love_-[32kbs]-_[YourDomain.com].mp3 	
Cat: rnb 	
Alpha: o	
has been added successfully

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.