How to read txt file interpreting the \n? [duplicate] - php

This question already has answers here:
How can I replace newline or \r\n with <br/>?
(10 answers)
Closed 7 years ago.
how to read a .txt file showing the html tag and interpreting the \n in the file.
I'm using a script php to read those files:
echo readfile("file.txt");
thanks.

You are looking for nl2br function.
echo nl2br(readfile("file.txt"));

Related

How to prevent PHP from renaming '&times' to 'x' symbol? [duplicate]

This question already has answers here:
Why is "&reg" being rendered as "®" without the bounding semicolon
(8 answers)
Should an ampersand be URL encoded in a query string?
(2 answers)
Closed 2 years ago.
I have with an unwanted replaced, and not able to figure out how to fix it.
When you echo the following string in PHP
echo('?hash=123&rid=111&timestamp=123');
The output is:
?hash=123&rid=111×tamp=123
Note that &timestamp has been replaced with ×tamp
I tried to escape it by using \&timestamp but that doens't work.
How can I prevent PHP replacing this?
You can reproduce this error online using http://phptester.net/
You have to escape that string, because & is a special symbol in HTML.
echo htmlspecialchars('?hash=123&rid=111&timestamp=123');
More information on the PHP site: https://www.php.net/manual/en/function.htmlspecialchars.php

Character strange html [duplicate]

This question already has answers here:
How do I remove ASCII number 13?
(1 answer)
PHP remove line break or CR LF with no success
(9 answers)
How to remove ANSI-Code ("
") from string in PHP
(4 answers)
Closed 4 years ago.
Ok, maybe is simple question but i am generating a xml from custom posts of wordpress, the problem is a textarea field of acf, i put a break line here and the code generate give me this character 
 but i not find nothing about that in google and str_replace not make nothing about that. i already remove the <br /> and <br> but that character I can't.
this is my actual code about that
str_replace('
', '', str_replace('<br />', '', strip_tags($addressValue['c_restaurant_map_address'], '<br /><br/><br>')));

Convert sting to html code using Laravel or PHP [duplicate]

This question already has answers here:
PHP Regex markdown from string
(1 answer)
Why is my PHP regex that parses Markdown links broken?
(2 answers)
PHP regex. Convert [text](url) to text [duplicate]
(1 answer)
Closed 4 years ago.
I have the following string :
this is sample text
[abc def.pdf](https://example.com/post/abc def.pdf)
This is another line after file upload
[dfg.pdf](https://example.com/post/dfg.pdf)
![IMG_3261.JPG](https://example.com/post/IMG_3261.JPG)
this are some other line append to sting.
I want to convert this string in to as follow.
this is sample text
abc def.pdf
This is another line after file upload
dfg.pdf
<img src="https://example.com/post/IMG_3261.JPG"/ title="IMG_3261.JPG">
this are some other line append to sting.
How could I do it using laravel or php?
I know I can do that using php function preg_replace but I am not good at REGEXP. So please help me to do it.
what i try so far
i try this solution
Why is my PHP regex that parses Markdown links broken?
But it will only converting to anchor tag but i also want to convert it to image tag too
preg_replace('#((https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?))#', '$1', $string);
but it will not get output i mention above. How can i do it.

How to find a character using index in PHP string? [duplicate]

This question already has answers here:
Finding a character at a specific position of a string
(5 answers)
Closed 5 years ago.
I have a string in PHP code like this:
$string = "This is a PHP code";
I want to find a character at index 3 in above string. And output must be:
s
Is there any idea to achieve this goal ?
If I understood your question properly, you want character at 3rd index then write following line ;)
echo $string[3];

Flie name with space in names does no get downloaded [duplicate]

This question already has answers here:
Using PHP Replace SPACES in URLS with %20
(6 answers)
Closed 7 years ago.
I am sending a link in email to download a file , problem is if the
file name contains spaces in filename it does not get down loaded.
example working:
Resume: http://www.procreations.in/resumes/14278870091CSS.docx
Not working:
http://www.procreations.in/resumes/14278880294Blog link.docx
How to solve Space files download problem ?
http://www.procreations.in/resumes/14278880294Blog%20link.docx
will work.
Replace space for %20

Categories