Web Analytics Made Easy -
StatCounter splitting a variable more than one way - CodingForum

Announcement

Collapse
No announcement yet.

splitting a variable more than one way

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • splitting a variable more than one way

    I currently use the following code to split a text file up so the first paragraph appears on the home page and then the user can click in to read the rest:

    @display = split(/<BR><BR>/, $small_story);
    $showtext = $display[0];

    Unfortuantely the text file sometimes has <BR> <BR> instead of <BR><BR> -- so how can I set the split up to use one or the other?

    Or do I have to take the $showtext and split it again looking for a <BR> <BR>?
    Last edited by zenweezil; Feb 6, 2004, 09:39 PM.

  • #2
    I am not sure if this will work, but try:
    @display = split(/<BR><BR>|<BR> <BR>/, $small_story);

    Comment


    • #3
      Or you can just do this:

      Code:
      @display = split(/<BR>\s*<BR>/, $small_story);
      The \s* tells perl that it may or not be a space between.

      Cheers

      Comment


      • #4
        Thanks - both ways worked fine

        Sometimes it's the simplest things that elude me.

        Comment


        • #5
          Originally posted by kidd
          Code:
          @display = split(/<BR>\s*<BR>/, $small_story);
          The \s* tells perl that it may or not be a space between.
          [/B]
          \s* actually tells perl to match any number (including zero) of white space characters surrounded by <BR>.

          Paul-Ecchi's way may be better, just for the sake of perfection.
          Code:
          @display = split(/<BR><BR>|<BR> <BR>/, $small_story);
          Code:
          @display = split(/<BR>(| )<BR>/, $small_story);
          would also work.

          so many ways! if you want some more...look up the General Quantifiers and other Metacharacters
          "There is more than one way to do it."

          Comment

          Working...
          X