Methods to remove specific characters from string

0 votes

I am trying to remove the brackets "[" and "]" from $widget_text in the variable value below and store the result in $widget_id.

$widget_text = '[widget_and-some-text]';
$widget_id = ?;

Should I use preg_replace, str_replace or something else?

Jun 11 in PHP by narikkadan
• 10,840 points
6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to remove all special characters from a string?

Hello @kartik, This should do what you're looking ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,720 points
5,964 views
0 votes
1 answer

How to remove new lines and returns from php string?

Hello @kartik, You need to place the \n in double ...READ MORE

answered Nov 19, 2020 in PHP by Niroj
• 82,720 points
362 views
0 votes
1 answer

How to concatenate text from multiple rows into a single text string in SQL server?

Hello @kartik, Use COALESCE: DECLARE @Names VARCHAR(8000) SELECT @Names = ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,720 points
1,958 views
0 votes
1 answer

How to get parameters from a URL string?

Hello @kartik, You can use the parse_url() and parse_str() for that. $parts = ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,720 points
211 views
0 votes
1 answer

How can I remove a specific item from an array?

Hello @kartik, Find the index of the array element you ...READ MORE

answered Aug 28, 2020 in PHP by Niroj
• 82,720 points
168 views
0 votes
1 answer

How to remove duplicate values from an array in PHP?

Hello @kartik, Use array_unique(): Example: $array = array(1, 2, 2, 3); $array ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,720 points
1,369 views
0 votes
1 answer

Generate SEO friendly URLs (slugs)

function format_uri( $string, $separator = '-' ) {     $accents_regex ...READ MORE

answered Feb 14 in Others by narikkadan
• 10,840 points
56 views
0 votes
1 answer

Generate SEO friendly URLs- Slugs

// source: https://code.google.com/archive/p/php-slugs/ function my_str_split($string) { ...READ MORE

answered Feb 22 in Others by narikkadan
• 10,840 points
57 views
0 votes
1 answer

How do I strip all spaces out of a string in PHP?

If I have understood your question right, ...READ MORE

answered Feb 23 in PHP by Aditya
• 7,280 points
90 views
0 votes
0 answers

Split string into 2 pieces by length using PHP

I want to split my long string ...READ MORE

Jun 1 in PHP by Kichu
• 19,040 points
11 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP