Jump to content

extracting data from string


Ortix

Recommended Posts

so I'm working on this system which requires me to inject anime show names into a DB for an index.

 

I get them in this form:

[Kira-Fansub]_HIGHSCHOOL_OF_THE_DEAD_-_04_(BD_1920x1080_x264_AAC) [F0E73009].mkv

 

I need to get it in this form: Highschool Of The Dead

 

sometimes the words are space seperated.

the main part is to extract the text in between the ] and ( and with that i mean [stuff]extract this(other stuff) and sometimes it looks like this: [stuff]extract[stuff]

 

I have NO CLUE how to do this preg_match_all doesn't get me any further.. maybe in stages?

Link to comment
Share on other sites

<?php
$name='[Kira-Fansub]_HIGHSCHOOL_OF_THE_DEAD_-_04_(BD_1920x1080_x264_AAC) [F0E73009].mkv';
$str=preg_replace(array('/(\s*?[\[(].*?[\])]\s*?)/','/(-.*)/','/(_)/','/(  )/'),array('','',' ',' '),$name);
echo $str;
?>

 

output

HIGHSCHOOL OF THE DEAD

How it works:

1st match ('/(\s*?[\[(].*?[\])]\s*?)/') catches [] and () items and removes them ('')

2nd match ('/(-.*)/') drops everything after the dash, including the dash ('')

3rd match (/(_)/) replaces underscores with spaces (' ')

4th match (/(  )/) Double spaces replaced with single space (' '):

 

Link to comment
Share on other sites

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.