Merge hyphenated word from string in PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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
Improve this question
Suppose a string contains "includ- ing" or "joi- ing". How would you search for and join hyphenated words in a string?

You could use a regular expression with preg_replace():
preg_replace('/-\s+/', '', $string);
This looks for a - followed by one or more whitespace characters and replaces them with the empty string.

// -- Get an array of words splitted with '- '
$splitted = explode('- ', $word);
// -- Rejoined words:
$joined = implode('', $splitted );

Related

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);

php query where a word like and skip before words [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
php script query out put is
"some word STAR some other words", I want remove all workd before "Star". I need all other words after "Star".
I using php script output from a mysql file
$newStr = substr_replace($str, '', 0, strpos($str,"STAR"));
Where $str is a variable with a string, eg: "some word STAR some other words"
$arrayStr = explode('STAR', 'some word STAR some other words');
echo $arrayStr[1];
DEMO
Some documentation:
php.net explode() function

How to use regex to get the numbers out of this type? [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 want a regex that will help me to get the 4 numbers before the cc.
The RegEx must contain the cc to identify these exact number.
Example:
1600cc
You should use:
/(\d{4})cc\b/
\b ensures that "cc" is at the and of the word.
preg_match('/(\d{4})cc/', $string, $match);
$match[1] will contain the number.

PHP Regular Expression difference [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
Can someone explain the difference between these two lines of code?
preg_replace("/[^0-9]/", '', $Phone);
preg_replace('/[^0-9\/+]/', '', $Phone);
Ive been hunting online and cant seem to find anything explaining the extra "/+"
The following matches anything that's not a digit.
/[^0-9]/
The following matches anything that's not a digit, /, or +:
/[^0-9/+]/

Replace HTML entities with regular expression [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 would like a regular expression in PHP to find all HTML entities such as "<br /> <br /> ..etc. " in order to remove them from a long string.
This one removes alpha, decimal and hex HTML entities:
$text = preg_replace('/&(?:[a-z\d]+|#\d+|#x[a-f\d]+);/i', '', $text);
Try using this regex... the [^\s]* one was capturing a whole lot other nonsense...
$text = preg_replace("/&(?:[a-z0-9]{2,8}|#[0-9]{2,3}+);/i", '', $text);
Try using strip_tags function, regex is not necessary here

Categories