String_Replace: LP6 vs. LP8 (line breaks)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

String_Replace: LP6 vs. LP8 (line breaks)

Israel Thompson
Hello all,

First off, I am using LP6 and LP8 and am noticing some differences in some
string replaces that I could use a little insight on.

In LP6 I have to use this code in a blog I have developed to show blog posts
with proper line breaks.

Variable: 'post_body_mod' = (String_Replace: (field: 'post_body'),
-find='\r', -Replace='<br />');
$post_body_mod = (String_Replace: $post_body_mod, -find='\r\n',
-Replace='<br />');
$post_body_mod = (String_Replace: $post_body_mod, -find='\n', -Replace='<br
/>');

<div class="blog_post_body">[Output: Variable: 'post_body_mod',
-EncodeNone]</div>


Now in LP8 I have to shorten my lines without searching for '\r\n' and '\r',
because the outputted blog posts have too many line breaks or <br />'s in
them.

Variable: 'post_body_mod' = (String_Replace: (field: 'post_body'),
-find='\n', -Replace='<br />');

<div class="blog_post_body">[Output: Variable: 'post_body_mod',
-EncodeNone]</div>

Why is this different in LP6 and LP8? Is there a better way to get more
consistency?

Thanks,

Israel Thompson




------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: String_Replace: LP6 vs. LP8 (line breaks)

Israel Thompson
Ok, I think I have found the solution.

Changing the order of my string_replace lines seems to balance out the
situation. Putting the find '\r\n' first, then the '\r' and '\n' produced
similar outputted results in LP6 and LP8.

Variable: 'post_body_mod' = (String_Replace: (field: 'post_body'), -find='
\r\n ', -Replace='<br />');
$post_body_mod = (String_Replace: (Variable: 'post_body_mod'), -find='\r ',
-Replace='<br />');
$post_body_mod = (String_Replace: (Variable: 'post_body_mod'), -find='\n',
-Replace='<br />');

Sincerely,

Israel Thompson


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: String_Replace: LP6 vs. LP8 (line breaks)

Bil Corry-3
Israel Thompson wrote:

> Ok, I think I have found the solution.
>
> Changing the order of my string_replace lines seems to balance out the
> situation. Putting the find '\r\n' first, then the '\r' and '\n' produced
> similar outputted results in LP6 and LP8.
>
> Variable: 'post_body_mod' = (String_Replace: (field: 'post_body'), -find='
> \r\n ', -Replace='<br />');
> $post_body_mod = (String_Replace: (Variable: 'post_body_mod'), -find='\r ',
> -Replace='<br />');
> $post_body_mod = (String_Replace: (Variable: 'post_body_mod'), -find='\n',
> -Replace='<br />');

I find it's easiest to just standardize the line endings using [lp_string_linefeedSet] - it will figure out the line endings and convert them appropriately:

  <http://tagSwap.net/lp_string_linefeedSet>

So your code would become:

  var:'post_body_mod' = (lp_string_linefeedSet:(field: 'post_body'),'<br />');


And note, you don't have to use [output], this works equally as well and is easier to read:

  <div class="blog_post_body">[$post_body_mod]</div>


The only other thing you might want to do is filter on XSS (cross-site scripting) if (field: 'post_body') is coming from potentially hostile users.


- Bil


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage