Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have an app that stores survey responses. Some of the responses are plain-text responses with feedback.
When the person filling the survey out adds a line (his return on the key board) this creates a new paragraph.
It is stored in my Postgres database as an ascii character chr(10) (referring to it in Postgres terms).
This is all fine however the problem I am running into is when I display the values. My PDF printing app doesn't understand this ascii encoding and displays it all as one line. Instead of:
One line
Two lines
Three lines
It returns it as:
One line Two lines three lines
Makes for very long drawn out paragraphs...
I am trying to figure out how I can replace the ascii code with an html break <br/>.
I am obviously familiar with str_replace - the point is that I am not familiar with ascii at all and need some help on how to search for this in the string to replace with an HTML break <br/>.
Thank you.
To replace line breaks with <br />, you can use the built-in PHP function nl2br
e.g.
$content = nl2br($content);
(technically it inserts the BRs before the line breaks, so they're still there, but should work ok)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to save chemistry equations in my database, equations for example:
`AB + O2 → Oxide of A & B`
Even typing here 2 is coming beside O whereas it's the symbol of oxygen like below:
Please note: If I am trying to directly copy and paste it in MySQL table field using phpMyAdmin, there also O2 is not getting saved as a symbol.
Note: MySQL field is text , collation is utf8mb4_general_ci.
Saving from php to mysql is next step. For now at least simply copying it (from phpMyAdmin) should work in MySQL.
I noticed that the subscript numbers on the web pages aren't actually subscripts, its just the HTML tag making it. (the <sub> tag).
So you have to use some kind of converter for it or do it yourself to convert it to actual unicode subscript.
If you want to print the equations to web page from database, you can save it with the HTML tag e.g.
H<sub>2</sub>O
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I would like to extract a JSON string within another string.
Currently I am getting the full string using file_get_contents and running the following pattern on the string: https://regex101.com/r/5jAucO/1
which pretty much gives multiple matches.
I would like to extract the JSON string that is saved in window._sharedData but haven't been able to achieve that. Does someone have any idea how I could do that?
Why not include _sharedData in the regex like?
_sharedData\s*=\s*\{.+\}
or with lookbehind:
(?<=_sharedData\s=)\s*\{.+\}
or take the json from a capturing group:
_sharedData\s*=\s*(\{.+\})
One concern with the lookbehind is if they add an additional whitespace character between _sharedData and = it won't match.
This only works well since there are no linebreaks in the JSON.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use PHP to find a value in a string and replace it with another value, the value may be (for example) £x on one line and £x.xx on the next, but will always be replaced by a value of £x.xx. Hope that makes sense? TIA.
Use this regex to match the prices: £[0-9]+\.?[0-9]{0,2}
You can perform the replace with this by using this function:
preg_replace("/£[0-9]+\.?[0-9]{0,2}/", " ** REPLACEMENT ** ", $input_lines);
The nice thing about preg_replace is that if you feed it a single line you'll get a single value back, but if you feed it an array of strings with the values you want changed it will return an array with those values replaces. Nice and tidy if you need to make a lot of replacements.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I build my web sit by wordpress. When i try to add feed function some issue occur.I use chrome visit the feed,log is :
This page contains the following errors:
error on line 134 at column 16: Input is not proper UTF-8, indicate encoding !
Bytes: 0x08 0xE8 0xBF 0x90
Below is a rendering of the page up to the first error.
I have checked the the blank of header.php.I also use fix rss plug-in, but it still can't be fix it. How do I check which file cause the error? my feed url is : http://www.songyang.net/feed/
It looks like the page here has invalid UTF-8 characters in it. The problem lies here:
首先,我们需要创建一个场景。接着在场景中放放置一个灯光, 最后在场景中放置一个物体, 将它上面挂载一个我们创建的组件。
**bad character here**运行程序后, 场景中会出现一个 UI 按钮, 点击它移动立方体。移动的路径通过两个动画拼接完成。
Delete the characters around there and re-type them, that should remove the invalid character.
It tells you where the bad character is because it renders the page up until the character. If you want, you can actually see the character by copy/pasting the section of text into a UTF-8 file in Notepad++. In this case, it comes out as a "BS" character!
bad character.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing my project and I am using php and MySQL
My program is reading a data from textarea as a list of people, I use the explode function to separate the list and then I generate a for loop to insert them to MySQL database
till this part I don't have any problems
The problem is when I query the database with a where condition specifying a name from the list it does not recognize it
My question does the explode function change any thing to the names in the list or add any special characters
because I use the same functionality with specific name and it goes smoothly
Thanks in advance
It should not. PHP explode will not change your text and the WHERE query should operate correctly.
Are the characters all utf8 encoded? Check the database and see what you are querying for actually exists the same way you are sending it.
Like the others said, if you can provide us an example of the following it would be great:
Actual textarea input (not exploded).
DB Dump of what is inserted.
Your QUERY to select
Additionally, it could be a space issues, use trim before you insert the data or in your query instead of field = '$a' do a field LIKE '%$a%'
I don't think explode() will modify anything. try to use trim() in your foreach loop before inserting. Might be some characters that can not be seen.