if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • so many sites so little time

    if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

    say i want spacing in my text so instead of doing
    <br>
    <br>
    in between the lines
    or having to do <href = or <a href = for a link
    what could i do to have php enter to mysql or retrive it formated?

  • Marcin Dobrucki

    #2
    Re: if i wanted to have the text i enter into a database be retrivedformate d the way i want it how could i do that

    so many sites so little time wrote:
    say i want spacing in my text so instead of doing
    <br>
    <br>
    in between the lines
    or having to do <href = or <a href = for a link
    what could i do to have php enter to mysql or retrive it formated?
    I don't quite understand what you are saying. Could you give an
    example of what text you have, and what you want to get out of it?

    Comment

    • Moot

      #3
      Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

      so many sites so little time wrote:
      say i want spacing in my text so instead of doing
      <br>
      <br>
      in between the lines
      or having to do <href = or <a href = for a link
      what could i do to have php enter to mysql or retrive it formated?
      Does this do what you want?
      Inserts HTML line breaks before all newlines in a string


      It would take care of the line spacing issue, but I don't quite
      understand what you want to do with links.

      Comment

      • Krustov

        #4
        Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

        <comp.lang.ph p>
        <so many sites so little time>
        <19 Nov 2006 21:17:23 -0800>
        <1163999843.263 104.309190@k70g 2000cwa.googleg roups.com>
        say i want spacing in my text so instead of doing
        <br>
        <br>
        in between the lines
        or having to do <href = or <a href = for a link
        what could i do to have php enter to mysql or retrive it formated?
        >
        If you mean you have a piece of bare text like http://www.whatever.com
        and you want to make it into a hyperlink after grabbing it from your
        database - then you could do something like the following .

        <?php

        $grab="http://www.whatever.co m";

        $extra="<a href=$grab>$gra b</a>";

        print $extra;

        ?>

        You could then store $extra in your database so it could be grabbed and
        displayed like the following .

        <?php

        # read $extra from database .

        print $extra;

        ?>


        --

        Comment

        • Geoff Berrow

          #5
          Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

          Message-ID: <MPG.1fcbc0a16d 76d94498a1e5@ne ws.newsreader.c omfrom
          Krustov contained the following:
          >or having to do <href = or <a href = for a link
          >what could i do to have php enter to mysql or retrive it formated?
          >>
          >
          >If you mean you have a piece of bare text like http://www.whatever.com
          >and you want to make it into a hyperlink after grabbing it from your
          >database - then you could do something like the following .
          >
          ><?php
          >
          >$grab="http://www.whatever.co m";
          >
          >$extra="<a href=$grab>$gra b</a>";
          >
          >print $extra;
          >
          >?>
          It could be that he wants to turn anything that just looks like a link
          into a link. That would involve a bit of regex (note to self: must put
          in effort to learn more regex...)



          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • so many sites so little time

            #6
            Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

            yeah i guess i should get into regex, basicly i should prob just make a
            button like most message boards do out of javascript to let them make
            it a link i think wordpress does it that way to... blah off to school
            Geoff Berrow wrote:
            Message-ID: <MPG.1fcbc0a16d 76d94498a1e5@ne ws.newsreader.c omfrom
            Krustov contained the following:
            >
            or having to do <href = or <a href = for a link
            what could i do to have php enter to mysql or retrive it formated?
            >
            If you mean you have a piece of bare text like http://www.whatever.com
            and you want to make it into a hyperlink after grabbing it from your
            database - then you could do something like the following .

            <?php

            $grab="http://www.whatever.co m";

            $extra="<a href=$grab>$gra b</a>";

            print $extra;

            ?>
            >
            It could be that he wants to turn anything that just looks like a link
            into a link. That would involve a bit of regex (note to self: must put
            in effort to learn more regex...)
            >
            >
            >
            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • so many sites so little time

              #7
              Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

              acutally what krustov said is more of what i want, as long as they
              write out the link http:// then it should work well.
              so many sites so little time wrote:
              yeah i guess i should get into regex, basicly i should prob just make a
              button like most message boards do out of javascript to let them make
              it a link i think wordpress does it that way to... blah off to school
              Geoff Berrow wrote:
              Message-ID: <MPG.1fcbc0a16d 76d94498a1e5@ne ws.newsreader.c omfrom
              Krustov contained the following:
              >or having to do <href = or <a href = for a link
              >what could i do to have php enter to mysql or retrive it formated?
              >>
              >
              >If you mean you have a piece of bare text like http://www.whatever.com
              >and you want to make it into a hyperlink after grabbing it from your
              >database - then you could do something like the following .
              >
              ><?php
              >
              >$grab="http://www.whatever.co m";
              >
              >$extra="<a href=$grab>$gra b</a>";
              >
              >print $extra;
              >
              >?>
              It could be that he wants to turn anything that just looks like a link
              into a link. That would involve a bit of regex (note to self: must put
              in effort to learn more regex...)



              --
              Geoff Berrow (put thecat out to email)
              It's only Usenet, no one dies.
              My opinions, not the committee's, mine.
              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

              Comment

              • malatestapunk

                #8
                Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                so many sites so little time wrote:
                acutally what krustov said is more of what i want, as long as they
                write out the link http:// then it should work well.
                so many sites so little time wrote:
                yeah i guess i should get into regex, basicly i should prob just make a
                button like most message boards do out of javascript to let them make
                it a link i think wordpress does it that way to... blah off to school
                Geoff Berrow wrote:
                Message-ID: <MPG.1fcbc0a16d 76d94498a1e5@ne ws.newsreader.c omfrom
                Krustov contained the following:
                >
                or having to do <href = or <a href = for a link
                what could i do to have php enter to mysql or retrive it formated?
                >

                If you mean you have a piece of bare text like http://www.whatever.com
                and you want to make it into a hyperlink after grabbing it from your
                database - then you could do something like the following .

                <?php

                $grab="http://www.whatever.co m";

                $extra="<a href=$grab>$gra b</a>";

                print $extra;

                ?>
                >
                It could be that he wants to turn anything that just looks like a link
                into a link. That would involve a bit of regex (note to self: must put
                in effort to learn more regex...)
                >
                >
                >
                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/


                If you want to search plain text for valid urls and replace them with
                links, here is a regex that may help you out:


                <?php
                $rx = '
                {
                \b
                # Match the leading part (proto://hostname, or just hostname)
                (
                # ftp://, http://, or https:// leading part
                (ftp|https?)://[-\w]+(\.\w[-\w]*)+
                |
                # or, try to find a hostname with our more specific
                sub-expression
                (?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \. )+ # sub domains
                # Now ending .com, etc. For these, require lowercase
                (?-i: com\b
                | edu\b
                | biz\b
                | gov\b
                | in(?:t|fo)\b # .int or .info
                | mil\b
                | net\b
                | org\b
                | [a-z][a-z]\b # two-letter country codes
                )
                )

                # Allow an optional port number
                ( : \d+ )?

                # The rest of the URL is optional, and begins with / . . .
                (

                /
                # The rest are heuristics for what seems to work well
                [^;"\'<>()\[\]{}\s\x7F-\xFF]*
                (?:
                [.,?]+ [^;"\'<>()\[\]{}\s\x7F-\xFF]+
                )*
                )?
                }x';

                $text = "blah blah http://www.google.com, text text more text etc";
                echo preg_replace ($rx, '<a href="\1">\1</a>', $text);
                ?>

                Comment

                • malatestapunk

                  #9
                  Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                  so many sites so little time wrote:
                  acutally what krustov said is more of what i want, as long as they
                  write out the link http:// then it should work well.
                  so many sites so little time wrote:
                  yeah i guess i should get into regex, basicly i should prob just make a
                  button like most message boards do out of javascript to let them make
                  it a link i think wordpress does it that way to... blah off to school
                  Geoff Berrow wrote:
                  Message-ID: <MPG.1fcbc0a16d 76d94498a1e5@ne ws.newsreader.c omfrom
                  Krustov contained the following:
                  >
                  or having to do <href = or <a href = for a link
                  what could i do to have php enter to mysql or retrive it formated?
                  >

                  If you mean you have a piece of bare text like http://www.whatever.com
                  and you want to make it into a hyperlink after grabbing it from your
                  database - then you could do something like the following .

                  <?php

                  $grab="http://www.whatever.co m";

                  $extra="<a href=$grab>$gra b</a>";

                  print $extra;

                  ?>
                  >
                  It could be that he wants to turn anything that just looks like a link
                  into a link. That would involve a bit of regex (note to self: must put
                  in effort to learn more regex...)
                  >
                  >
                  >
                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/


                  If you want to search plain text for valid urls and replace them with
                  links, here is a regex that may help you out:


                  <?php
                  $rx = '
                  {
                  \b
                  # Match the leading part (proto://hostname, or just hostname)
                  (
                  # ftp://, http://, or https:// leading part
                  (ftp|https?)://[-\w]+(\.\w[-\w]*)+
                  |
                  # or, try to find a hostname with our more specific
                  sub-expression
                  (?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \. )+ # sub domains
                  # Now ending .com, etc. For these, require lowercase
                  (?-i: com\b
                  | edu\b
                  | biz\b
                  | gov\b
                  | in(?:t|fo)\b # .int or .info
                  | mil\b
                  | net\b
                  | org\b
                  | [a-z][a-z]\b # two-letter country codes
                  )
                  )

                  # Allow an optional port number
                  ( : \d+ )?

                  # The rest of the URL is optional, and begins with / . . .
                  (

                  /
                  # The rest are heuristics for what seems to work well
                  [^;"\'<>()\[\]{}\s\x7F-\xFF]*
                  (?:
                  [.,?]+ [^;"\'<>()\[\]{}\s\x7F-\xFF]+
                  )*
                  )?
                  }x';

                  $text = "blah blah http://www.google.com, text text more text etc";
                  echo preg_replace ($rx, '<a href="\1">\1</a>', $text);
                  ?>

                  Comment

                  • malatestapunk

                    #10
                    Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                    Of course, that was from "Mastering Regular Expressions, 2nd Edition",
                    by Jeffrey E. F. Friedl. It's a great book - definitely a must-read.

                    Comment

                    • so many sites so little time

                      #11
                      Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                      ok wow im most def. gonna use that and tweak it a bit what i really
                      well what my freind told me i need to figure out is on a message board
                      the whole bb code i guess it is where you have the buttons above the
                      textbox and you click bold and it inserts a bold <b></bwhere you are
                      typing or before the word and after the word if highllighted there must
                      be some scripts online or i think its gotto be javascript i dunno if i
                      knew what lang it was it wouldnt be so hard, you know what im talking
                      about right its got the little chainlink for if you want a link and
                      stuff like that
                      malatestapunk wrote:
                      Of course, that was from "Mastering Regular Expressions, 2nd Edition",
                      by Jeffrey E. F. Friedl. It's a great book - definitely a must-read.

                      Comment

                      • so many sites so little time

                        #12
                        Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                        one last quick thing can i have lets say $text be something like $a =
                        $b & $c
                        malatestapunk wrote:
                        Of course, that was from "Mastering Regular Expressions, 2nd Edition",
                        by Jeffrey E. F. Friedl. It's a great book - definitely a must-read.

                        Comment

                        • so many sites so little time

                          #13
                          Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that

                          like can one var = 2 others
                          so many sites so little time wrote:
                          one last quick thing can i have lets say $text be something like $a =
                          $b & $c
                          malatestapunk wrote:
                          Of course, that was from "Mastering Regular Expressions, 2nd Edition",
                          by Jeffrey E. F. Friedl. It's a great book - definitely a must-read.

                          Comment

                          • malatestapunk

                            #14
                            Re: if i wanted to have the text i enter into a database be retrived formated the way i want it how could i do that


                            so many sites so little time wrote:
                            like can one var = 2 others
                            so many sites so little time wrote:
                            one last quick thing can i have lets say $text be something like $a =
                            $b & $c
                            malatestapunk wrote:
                            Of course, that was from "Mastering Regular Expressions, 2nd Edition",
                            by Jeffrey E. F. Friedl. It's a great book - definitely a must-read.
                            I'm not sure I understand - but if jou just want to concatenate two
                            strings (append one string to the other one), you can do it like this:

                            $s1 = "bla"; $s2 = "a string";
                            echo $s1 . $s2; // output: blaa string
                            // OR
                            echo "$s1 $s2" // Note: only double quotes here. Output: bla a string

                            As for the BBCode - it is a specific markup language, where you put
                            tags in square brackets (as in '...' for bold, etc) - just like
                            you have in some forums. It's not HTML. There are ready-made PHP
                            libraries for conversion of BBCode to HTML - check out PHPClasses, for
                            example. I guess there are some javascript editors (like the one you
                            described), but I don't have any experience with them.

                            There are also some javascript HTML editors, and you can use them
                            instead of BBCode to get HTML right away (note: you really should do
                            some xss filtering). I kind of like TinyMC Editor
                            (http://tinymce.moxiecode.com/), some others prefer FCKEditor
                            (http://www.fckeditor.net/). There are some others too, so you may want
                            to do some googling.

                            But if you consider BBCode, you may also want to look at some other
                            (IMHO, better) markup alternatives - Textile
                            (http://jimandlissa.com/project/textilephp) and Markdown
                            (http://www.michelf.com/projects/php-markdown/). They both have syntax
                            similar to the one used in Wikis (eg. *bold* for bold, etc), and they
                            both produce valid (x)HTML. It's basically the same approach as with
                            BBCode (your users input something that's not HTML, but you use some
                            PHP code to convert that input into valid HTML), but it's easier to
                            type and read. No ready-made javascript editors (that I know of) for
                            these, though.

                            Comment

                            Working...