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, 2022 in PHP by narikkadan
• 63,600 points
459 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,840 points
11,453 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,840 points
16,794 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,840 points
3,078 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,840 points
865 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,840 points
766 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,840 points
2,737 views
0 votes
1 answer

Generate SEO friendly URLs (slugs)

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

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
594 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, 2022 in Others by narikkadan
• 63,600 points
559 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, 2022 in PHP by Aditya
• 7,680 points
1,199 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, 2022 in PHP by Kichu
• 19,040 points
722 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP