remove white space before after of data in text area [duplicate] - php

This question already has answers here:
How do I strip all spaces out of a string in PHP? [duplicate]
(4 answers)
Closed 5 years ago.
I input string to textarea such as below:
email1#gmail.com
email#gmail.com
email3#gmail.com
email4#gmail.com
How to format they to:
email1#gmail.com
email#gmail.com
email3#gmail.com
email4#gmail.com
One email in one line in textarea. I want use PHP to make it.
Please help me about solution, thanks you.

this should work in php
str_replace(' ','',$yourText)

If you want to remove all whitespace:
$str = preg_replace('/\s+/', '', $yourstring);

Use the trim function to do this.
return(trim($str));

Related

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.

nl2br() function ads <br> if no character is entered after/in the next line [duplicate]

This question already has answers here:
How to save Textarea input after convert line breaks as BR in SQL
(2 answers)
Closed 6 years ago.
I am using nl2br function with str_replace as follows:
$data = (!empty($_POST['content']))?nl2br($_POST['content']):null;
$data_fix = str_replace(array("\r", "\n"), '', $data);
When I insert data into database next lines automatically receives a <br>. Okay fine. To 95% extent this is what I want. But if there is no character entered after the next line in <textarea> it still enters a <br>.
Example:
What I want:
Hello Stackoverflow!<br>I am new here.
(new line space eliminated)
What I get:
Hellow Stactoverflow!<br>I am new here.<br>
(new line space inserted)
Please help me solve this!
trim() function will prevent adding extra <br> which are not needed if there is no text entered in or after the next line!
Simply replaced
$data = (!empty($_POST['content']))?nl2br($_POST['content']):null;
With
$data = (!empty($_POST['content']))?nl2br(trim($_POST['content'])):null;
And it did the job! But trim() should be after the nl2br() otherwise it won't work!
Answered my own question for future reference of other people seeking solution to the same!

How to remove white space in PHP generate css class? [duplicate]

This question already has answers here:
How do I strip all spaces out of a string in PHP? [duplicate]
(4 answers)
Closed 6 years ago.
I would like to remove white space in a php generated css code, I have different title header which would like to generate through php code.
Titles are like 1) Baby Day Care 2) Baby Night Care
My php codes are like:
<div class="wistia<?php echo $subject->title;?>">
So when I got the class, I got like wistiaBaby Day Care or wistiaBaby Night Care
But I want the class will be look like wistiaBabyDayCare or wistiaBabyNightCare
(I want space removed between text).
So how I am going to achieve that?
That should to the trick:
<div class="wistia<?php echo str_replace(' ', '', $subject->title);?>">
This just uses the str_replace function where you replace the first character with the 2nd character for a given string.
To remove any whitespace simply use preg_replace (regex):
<div class="wistia<?php echo preg_replace('/\s+/', '', $subject->title);?>">

Need to replace deprecated ereg_replace [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 9 years ago.
I am working for a non-profit and i'm not an expert in PHP.
I need to replace the following code:
$status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "\\0", $status);
When I attempt to modify it to preg_replace, I get an error every different way I try to exit the code.
This will do the job:
$statut = preg_replace('~[a-z]+://[^<>\s]+[\w/]~i', '$0', $statut);
But if the goal of this replacement is to keep all urls and transform them into links, you must change the pattern a little. And, why not, test them with filter_validate_url

Categories