Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: To Code a Line Break

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Great! As I said before - any questions/problems, just let me know. Oh, and it's always possible there's a simpler or more efficient method. But I feel confident this is at the very least serviceable.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #12
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    John, the original problem arose on account of my inability to communicate to my text editor (Notepad) that I wanted to search for hard returns. When I entered a hard return that I wanted interpreted as part of a search string character, the text editor interpreted it instead as a hard return end of line. You solved that problem by suggesting that, in place of hard returns, I should use hexadecimal ascii replacement characters, i.e. "\x0d\x0a\x0d\x0a".

    Your solution made my php code do exactly what I wanted it to do. Part of your solution, however, was to replace str_replace with preg_replace. On reviewing your solution, I speculated that, using your hexadecimal ascii substitutions, I ought to be able to implement your solution more simply by using str_replace. I attempted to do that. More particularly, in place of
    PHP Code:
    trim(preg_replace('"<br />[\x0d\x0a]*<br />[\x0d\x0a]*"'"<br />\n<br />\n“"$testitable [$element 2])); 
    I used
    PHP Code:
    trim(str_replace("\x0d\x0a\x0d\x0a""\x0d\x0a\x0d\x0a“"$testitable [$element 2])); 
    My substitution yields strange results. More particularly, what it causes is to not begin text following two hard returns with two hard returns followed by “ (open quote). Rather, what it causes is to append two “'s at the end of $testitable [$element + 2], regardless of whether that element contains zero, one, or more than one double hard return. You can see those incorrect results at http://www.njexpungements.com/test.php .

    I believe I'm getting closer in my quest for simplification, but I'm obviously not there yet. So my question is, must I use preg_replace, or can I accomplish the same thing with str_replace? In the meanwhile, as mentioned above, your suggested code is (to use your term) serviceable, for which you have my continuing thanks.

    A.
    Last edited by marain; 12-21-2014 at 01:15 AM. Reason: Minor "clean up." Substance not changed.

  3. #13
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    Got it!
    PHP Code:
    echo "Comment of former client" $testitable [$element] . "(file " $testitable [$element 1] . "):  “" trim(str_replace("<br />\x0d\x0a<br />""<br />\x0d\x0a<br />“"$testitable [$element 2])) . "”<br /><br />[For comments of other former clients, see our <a href='testimonials.php'>testimonials </a> page.]<br /><br />"
    Thank you!

    A.

Similar Threads

  1. GD Image - Line Break?
    By Vernier in forum PHP
    Replies: 7
    Last Post: 08-16-2012, 02:53 PM
  2. CSS Extra Line Break
    By Johnnymushio in forum CSS
    Replies: 2
    Last Post: 04-07-2011, 06:15 PM
  3. line break in mySql
    By ggalan in forum MySQL and other databases
    Replies: 4
    Last Post: 07-29-2010, 05:25 AM
  4. line break before pre tag, get rid of
    By chopficaro in forum CSS
    Replies: 4
    Last Post: 03-16-2010, 01:31 AM
  5. IE adds line break?
    By thenajsays in forum CSS
    Replies: 4
    Last Post: 06-10-2008, 04:13 PM

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
  •