How can I do a search and replace for this Carriage Return character?
'↵'
Here is a typical result in a Data Binding
N/S/F Wing + Liner + Trim ↵N/S/F Door + Foil + Trim ↵N/S/R Door + Foils ↵N/S/R Road Wheel + Tyre ↵Trims Clips and Sundries
I have tried this but doesn’t work
In PHP I can do this ('str_replace'
) which does work
<?php echo str_replace(array("\r\n\r\n", "\r\n", "\r", "\n", ","),"<br>",$_SESSION['for_PDF']['meth_replace']); ?>
Antony
March 10, 2021, 3:02pm
2
Hey @UKRiggers , did you work out the answer to this? I have the same problem!
I know this is one option I used
dmx-bind:value="sc_ad_job_q.data.sa_q_job_q.meth_specialist.replace(',', '\r')"
Antony
March 10, 2021, 3:11pm
4
@UKRiggers , that is good for creating a new line…
I want to replace a new line created from a textarea with a <br>
… did you find a way to do this?
Or @teodor , can you help us here?
I’ve tried:
.replace('\n', '<br>')
.replace('\\n', '<br>')
.replace('\r', '<br>')
.replace('\r\n', '<br>')
I’m using PHP…
Will it not work the other way round?
.replace('\r', '<br>')
Scrap that then
try
.replace(/\r?\n/g, '<br>')
Antony
March 10, 2021, 3:35pm
7
@patrick , that doesn’t work either!
.replace(/\r?\n/g,'<br>')
Seems that php doesn’t support regexp like app connect. The .replace('\n', '<br>')
should work.
Please check directly in the generated php file what the expression is, I noticed when I tested that in my test case the \n
did get escaped to \\n
in the code.
Antony
March 10, 2021, 4:59pm
9
Hi there @patrick …
Yes, I’ve been able to fix it by replacing \\n
to \n
in the PHP source code.
That is not an easy fix to sustain, as it resets to \\n
whenever I do a save of the server action file!
Best wishes,
Antony.
Antony
March 10, 2021, 5:09pm
10
I've submitted a bug report!
Wappler Version: 7.8.2
Server Type: PHP
Expected behavior
What do you think should happen?
In a .replace(), Wappler needs to retain the value of \n within the PHP it creates.
Actual behavior
What actually happens?
The value of \n is replaced with \\n and the new line is not found and replaced.
Patrick knows all the details and documented them here…