Title: Function to replace part of string
Last modified: September 16, 2017

---

# Function to replace part of string

 *  Resolved [pnbnsv](https://wordpress.org/support/users/pnbnsv/)
 * (@pnbnsv)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/function-to-replace-part-of-string/)
 * Hi there,
 * I am trying to create a PHP function to replace part of the string of a value
   in a field to export. The values in that field are like “Referência R999999” 
   and I just want to remove the “Referência ” part and let the rest as it is. I
   tried this but doesn’t work:
 * function corrige_referencia($ref) {
    str_replace(“Referência “,””,”$ref”); }
 * Any help, please?

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/function-to-replace-part-of-string/#post-9514637)
 * Hi [@pnbnsv](https://wordpress.org/support/users/pnbnsv/)
 * Please try the following code instead:
 *     ```
       function corrige_referencia( $ref ) {
       	$ref = str_replace( "Referência ", "", $ref );
       	return $ref;
       }
       ```
   
 *  Thread Starter [pnbnsv](https://wordpress.org/support/users/pnbnsv/)
 * (@pnbnsv)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/function-to-replace-part-of-string/#post-9517667)
 * Hi,
 * I am using:
 * <?php
    function corrige_referencia($ref) { return str_replace(“Referência “,””,
   $ref); } ?>
 * And it works.
 * Thank you very much for your help!
 *  [Mauricio Gelves](https://wordpress.org/support/users/mgelves/)
 * (@mgelves)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/function-to-replace-part-of-string/#post-9527089)
 * [@pnbnsv](https://wordpress.org/support/users/pnbnsv/), please, don’t forget 
   to mark this ticket as solved.
    (márcalo como resuelto así sirve para los demás
   usuarios 😉 ).

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

The topic ‘Function to replace part of string’ is closed to new replies.

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

 * 3 replies
 * 3 participants
 * Last reply from: [Mauricio Gelves](https://wordpress.org/support/users/mgelves/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/function-to-replace-part-of-string/#post-9527089)
 * Status: resolved