ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Find and Replace with Blank

August 02, 2011 10:35am

Subscribe [3]
  • #1 / Aug 02, 2011 10:35am

    dmacli

    141 posts

    Hello all!

    I am trying to take a custom field and replace a string with blank.  Basically what I want to do is:

    Turn this - http://www.twitter.com/#!/abc

    Into this - abc


    However, it seems like the find and replace utility doesnt allow you to replace something with nothing.  Is there a way around this?

  • #2 / Aug 03, 2011 5:44am

    John Henry Donovan

    12339 posts

    dmacli,

    What is your goal here?

    Do you just wish to display the abc segment of the field?

    Using the find and replace utility would mean that it would be a permanent change. It would completely remove the twitter part.

    So I would recommend this plugin
    Parses URL in a string and returns only certain parts of those URLs like just the domain and path.

    Would that help?

    If not there is also a Replace plugin that allows you to use some regex

  • #3 / Aug 03, 2011 11:13am

    dmacli

    141 posts

    Hey John,

    Yes, I would like to remove the entire string permanently.  Those are really useful though!  Thank you.

    However, is there a real simple way to totally delete the portion of the string permanently?  I ask because my site is very big (250K page views a day) so if possible I would rather do the work once on SQL than have a plugin run every time, even if the plugin is doing very little.

    So basically I would like to find and replace http://twitter.com/#!/ with blank and just leave the users twitter handle.

    Thanks!

    DM

  • #4 / Aug 04, 2011 3:37pm

    Sue Crocker

    26054 posts

    Hi, DM. You’d either need to use a plugin or some sort of PHP code to trim off that bit of the info. You could build an extension to make the changes needed as you save the entry. Does that make sense?

  • #5 / Aug 05, 2011 12:21pm

    dmacli

    141 posts

    I actually used the SQL query box in EE utilities and it worked.  Here is what I ran!

    update exp_weblog_data set field_id_129 = REPLACE(field_id_129, 'http://twitter.com/', '') where field_id_129 like 'http://twitter.com/%';
    update exp_weblog_data set field_id_129 = REPLACE(field_id_129, 'https://twitter.com/', '') where field_id_129 like 'https://twitter.com/%';
    update exp_weblog_data set field_id_129 = REPLACE(field_id_129, 'http://www.twitter.com/', '') where field_id_129 like 'http://www.twitter.com/%';
    update exp_weblog_data set field_id_129 = REPLACE(field_id_129, '#!/', '') where field_id_129 like '#!/%';
  • #6 / Aug 05, 2011 12:29pm

    Sue Crocker

    26054 posts

    That works. 😊 You could make a cron job to automate it. If anything else comes up, please do let us know in a new thread..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases