Remove special characters in string [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am currently doing this:
$a = 'some string with special characters';
$a = htmlentities($a);
$a = trim(preg_replace('/&#?[a-z0-9]+;/i', '', $a));
This works but I am wondering if there's a more efficient way to do this?

it contains certain characters like  and I want to remove those.
Try utf8_decode, or more feature-filled:
$output = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $input);
Documentation
The reason I bring this up is because what you are seeing are encoding issues, not "special characters".

Related

How can I use a regex in php to get characters at the end of a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I would like to parse a string and get characters from the end back to the first slash in the string. The string may change.
An example may be:
'string4\string3\string2\string1'
And I would want string1 from this example.
Another example string is:
'string3\string2\string1'
And I would like to get string1 from this example. Can this be done in php using regular expressions?
Just break the string apart by the \ character and get the last part:
$parts = explode('\\', $string);
echo $parts[count($parts) - 1];
Demo

How to string Concatenate with 'ENTER' value in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need a method that concatenate string with enter. As an example my string "Apple", "Box".
That string needs to be as:
$mynewstring = "Apple
Box"
Not as:
$mynewstring ="Apple "."\n"."Box" or $mynewstring ="Apple "."<br>"."Box"
Please tell how to do this.
Just do like this..
<?php
$mynewstring = "Apple,Box";
$arr=explode(",",$mynewstring);
echo(implode(PHP_EOL,$arr));
OUTPUT :
Apple
Box
If your variable is a part of DOM(browser related operation), then consider using <br/>, and use \n if using with php CLI.

PHP superscript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Is there any way that I can get o identify characters like(trademark, superscripts, numbers) from text or text file(but these characters are't in HTML code) and replace them using php
Example:
Get from text: ™ replace with PHP: (TM)
Yes, just parse your strings with str_replace.
Note that str_replace can use arrays, so you can replace multiple strings at once:
$text = "Text™®";
$text = str_replace(['™', '®'], ['(TM)', '(R)'], $text);
print $text;

Allow letters, digits and certain characters and delete the rest [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
when user submit a form input text
i want it just to allow a-z 0-9 and -_ just this numbers digits and -_
how do i check the input and make it only this inputs allows and delete the rest
Thank You!
$output = preg_replace("/[^a-zA-Z0-9_\-]/", '', $input);
function validate($value){
return preg_match("/^[a-zA-Z0-9_\-]*$/", $value) !== 0;
}
If the return value is false then you have invalid characters, if it true, everything is correct.
$input = preg_replace("/[^0-9a-z\_\-]/i", "", $_POST["myfield"]);
Use regexp.

Formatting a string in PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm going through sprintf() and other string formatting functions, but I have been unable to find an exact solution for stripping certain types of characters from a string. I wrote a function for this purpose (which seems quite nasty and not at all worth sharing here) but I am sure there is a easier way for what I am looking for.
$var = "abc244$%!";
now I want to format it this way:
$alpha = some_function($var); // alphabets only
$num = some_function($var); // numbers only
$alpha2 = some_function($var); // alphabets and special characters, no numbers.
To strip everything except numbers, use this:
$allnums=preg_replace("/[^0-9]/","",$var);
For all letters:
$letters=preg_replace('/\PL/u', "", $var);
For special chars:
$specialchars=preg_replace("/[a-zA-Z0-9]/", "", $var);

Categories