Title: Explode function on the_title
Last modified: August 19, 2016

---

# Explode function on the_title

 *  [abovegrnd](https://wordpress.org/support/users/abovegrnd/)
 * (@abovegrnd)
 * [16 years ago](https://wordpress.org/support/topic/explode-function-on-the_title/)
 * I have a section of my website where we post new tracks from various artists.
   I want to take the title of those tracks and break them down into “artist” and“
   song” so that I can style them differently and use them in various places in 
   my template.
 * It should be a simple process; all of the post titles are formatted like you 
   might expect (“Artist – Song name”)
 * For some reason, no matter what I do I cannot split this string (the_title) at
   the dash (” – “) and return anything of value.
 * I used a combination of strpos() and subsr(), I tried strstr(), and I’ve now 
   tried using explode() — and for some reason it’s no good.
 * If you look at the code, $firstName[0] SHOULD be the artist name (occurring before”–“)
   but for some reason it just returns the entire title.
    When I used strstr() and
   strpos/substr it just returned blank. Someone please help me, I’m pulling my 
   hair out!
 *     ```
       <ul style="border-top: 1px solid #9e9e9e; width:250px; float: right; padding: 0; margin-right: 5px;">
       <span style="background-color: #9e9e9e; color: #FFF; font-weight: bold; width: 250px;">NEW JOINTS</span>
       <?php query_posts('showposts=10&offset=0&cat=562'); ?>
       <?php while (have_posts()) : the_post('', '', FALSE); ?>
       <li style="padding: 10px 5px; border-bottom:1px solid #9e9e9e; font-size: small; list-style-type: none;">
       <?php
       $firstName = explode(" – ",the_title('','',false));
       echo $firstName[0];
       ?>
       </li>
       <?php endwhile; ?>
       </ul>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [abovegrnd](https://wordpress.org/support/users/abovegrnd/)
 * (@abovegrnd)
 * [16 years ago](https://wordpress.org/support/topic/explode-function-on-the_title/#post-1506854)
 * After further testing it seems that it works with any other delimiter other than“-”
   or ” – “. So, it seems to have trouble picking up the dash in the middle, anyone
   have any idea why that might be?

Viewing 1 replies (of 1 total)

The topic ‘Explode function on the_title’ is closed to new replies.

## Tags

 * [explode](https://wordpress.org/support/topic-tag/explode/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [the_title](https://wordpress.org/support/topic-tag/the_title/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [abovegrnd](https://wordpress.org/support/users/abovegrnd/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/explode-function-on-the_title/#post-1506854)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
