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;
Related
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
Could somebody tell me the regular expression for replacing everything outside of quote marks with white space?
Example text :
permalink_title='$permalink_title',
code_size_3='$code_size_3',
code_size_3='$code_size_3',
code_size_35='$code_size_35',
code_size_4='$code_size_4',
code_size_45='$code_size_45',
code_size_5='$code_size_5',
code_size_55='$code_size_55',
code_size_6='$code_size_6',
code_size_65='$code_size_65',
code_size_7='$code_size_7',
code_size_75='$code_size_75',
code_size_8='$code_size_8',
code_size_85='$code_size_85',
code_size_9='$code_size_9',
code_size_95='$code_size_95',
code_size_10='$code_size_10',
code_size_105='$code_size_105',
So the expression would replace everything outside of '$permalink_title' with whitespace. Ideally it would go one better and replace everything with whitespace leaving only the PHP variable - $permalink_title
*Note - I was going to perform this function with Komodo Edit or Notepad++
Any help would be great.
Use this regex :
(^[^']+|(?<=')[^']+$)
Debuggex Demo
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".
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
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.
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
I'm trying to validate for UK phone numbers - the specific requirements I have are:
must only consist of digits
the only non-digit characters allowed are space and dash
must begin with a zero
Can anyone suggest a nice and simple regular expression I can use for this?
Try with following regex:
^0([ -]\d+)*\d+$