-3

I have a variable $name which can sometimes contain spaces and special characters like '%' '&' etc.how can I remove all of those using regex or in any other way?

 */ public function handle() { $urls = Business::pluck('ical'); $names = Business::pluck('name'); foreach ($urls as $url) { foreach ($names as $name) { $test= explode("\n", $name); dd($test); $response = Curl::to($url) ->download('ical/'.$name.'.ics'); } 
0

1 Answer 1

0

Use the preg_replace() function of PHP.

$name = preg_replace('/[^\w\d]+/', '', $name); 

The regex /[^\w\d]+/ matches all white space and special characters.

https://www.tinywebhut.com/regex/2

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.