SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stripping <p> tag in HTMLArea

    When one copies and pastes into HTMLArea or begins typing then removes everything it puts in a <p> tag that when displayed on my site creates an annoying space between the title and the text of an article. Is there a way to find out if there is an opening <p> tag at the beginning of the string that is sent to the database and strip it out so as not to create that annoying space?

    On the HTMLArea site forum there is a post that references some "unclean" function that looks something like this:
    Code:
     unclean = unclean.replace(/^\s/i, ''); //Removes Spaces on the beginning 
    unclean = unclean.replace(/\s$/i, ''); //Removes Spaces on the end 
    unclean = unclean.replace(/^<P>/i, ''); //Removes beginning <P> 
    unclean = unclean.replace(/<P>$/i, ''); //Removes last <P>
    However I seem to be unable to find this unclean function. If anyone has experienced this or knows how to do this in php it would be greatly appreciated.

  2. #2
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you could use

    PHP Code:
    $string=ltrim('<p>',$string);
    $string=rtrim('</p>',$string); 
    It would strip the <p>-tag if the string starts with it and it will strip </p> if the strings ends with it.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at this WYSIWYG editor. It has php/asp/cfm hacks that lets you save from the editor to your db, so you can perform string manipulations to the file before it is inserted. It is pretty easy to customize if you know a little JS.

    http://www.openmymind.net/download.p...ted+desc&cmd=s

  4. #4
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did it this way:
    PHP Code:
    $string=ltrim('<p>',$string);
    $string=rtrim('</p>',$string); 
    And basically it ignored the entire string except for the close </p> tag which it affectionatley placed into my database then I switched it around to this:
    PHP Code:
    $string=ltrim($string,'<p>');
    $string=rtrim($string,'</p>'); 
    And it didnt change anything it inserted the entire string with the beginning and closing <p> tags.

    Upon further review I think the ltrim() and rtrim() are for spaces,\n,\r,\t,\v, and \o from the beginning or end of a string.

    Id really rather not switch editors now I use this one throughout the site and I really like it. This seems like it should be an easy problem to solve.

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $string preg_replace('/^\s*?<p[^>]*?>\s*(.*?)\s*<\/p>\s*?$/si''\1'$string); 
    That may work for you. You could also theoretically use a combination of trim() and substr(), but oh well.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect Thanks Jeff!

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanmayhew
    I did it this way:
    PHP Code:
    $string=ltrim('<p>',$string);
    $string=rtrim('</p>',$string); 
    And basically it ignored the entire string except for the close </p> tag which it affectionatley placed into my database then I switched it around to this:
    PHP Code:
    $string=ltrim($string,'<p>');
    $string=rtrim($string,'</p>'); 
    And it didnt change anything it inserted the entire string with the beginning and closing <p> tags.

    Upon further review I think the ltrim() and rtrim() are for spaces,\n,\r,\t,\v, and \o from the beginning or end of a string.

    Id really rather not switch editors now I use this one throughout the site and I really like it. This seems like it should be an easy problem to solve.
    You're right, it's the other way round.
    However, you can use the functions just as I told you, but the string really has to begin with <p>, there is nothing allowed in front of it.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here 's the file you can also use for custom written tags

    PHP Code:

    <tag:something></tag:something>

    or 

    <
    something></something
    for more help on it contact me armando.ota@rs-pi.com
    Attached Files Attached Files


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •