Title: Remove everything before specific character
Last modified: October 23, 2019

---

# Remove everything before specific character

 *  Resolved [briify](https://wordpress.org/support/users/briify/)
 * (@briify)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/remove-everything-before-specific-character/)
 * Hi,
 * We need to remove everything before a specific character in a product attribute.
   Example:
    Product attribute (sizes): 10042-25-XS We want to change it to only:
   XS
 * In the product attribute we have added the following:
    `[strtest({merchant_product_id[
   1]})]` Screenshot: [https://prnt.sc/pn27oq](https://prnt.sc/pn27oq)
 * So far we have added the following code to our functions.php, but it doesn’t 
   seem to work:
 *     ```
       function strtest( $str, $char, $strpos) {
       		$str = merchant_product_id[1]; 
                       $char =  " - "; 
       		$strpos = strpos($str, $char); 
       		$str = substr($str, $strpos+strlen($char)); //Extract the substring after the separator
       		echo $str;
       }
       ```
   
 * Screenshot:
    [https://prnt.sc/pn27a1](https://prnt.sc/pn27a1)
 * Hope you can help 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/remove-everything-before-specific-character/#post-12058785)
 * Hi [@briify](https://wordpress.org/support/users/briify/)
 * Please try this function:
 *     ```
       function my_get_value( $attribute = '' ) {
       	if ( empty( $attribute ) ) return;
       	$attribute = explode( "-", $attribute );
       	return array_pop( $attribute );
       }
       ```
   
 *  Thread Starter [briify](https://wordpress.org/support/users/briify/)
 * (@briify)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/remove-everything-before-specific-character/#post-12059108)
 * Hi again,
 * Your function is working, so that is great. But I can see now, that I didn’t 
   formulate me right since we also want to remove the `-` after everything before
   that character is removed.
 * To make it clear:
    Screenshot of how the function is working now: [https://prnt.sc/pn849f](https://prnt.sc/pn849f)
   We then want to remove the `-` too.
 * Thank you already 🙂
 *  Thread Starter [briify](https://wordpress.org/support/users/briify/)
 * (@briify)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/remove-everything-before-specific-character/#post-12063343)
 * Hi,
 * I tried reuploading the CSV-file and rerun code again, now it seems to work!
 * Thank you 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Remove everything before specific character’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)

 * 3 replies
 * 2 participants
 * Last reply from: [briify](https://wordpress.org/support/users/briify/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/remove-everything-before-specific-character/#post-12063343)
 * Status: resolved