Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to know how to verify that the user entered empty string in a sentence if in a string with multiple spaces in blank
Example
" "
if user entered a emṕty string, the program must show an alert as this
echo "The username must not be empty";
Use trim to remove whitespace from a var...
$name = trim($_GET['name']);
if ($name == '') //empty
Try this
if (strlen(trim($yourString)) == 0) {
// Do something
}
If the length of the string is 0 after the spaces are trimmed/removed.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a function that builds a regex based on an array. The problem is that PHP keeps adding backslashes to some of the characters, and it keeps messing up the regex.
Here is my function:
private static $allowedPermissions = [
/*SV*/
'user_add',
'user_edit',
'user_delete',
'user_view'];
$regexrule = '/';
foreach (self::$allowedPermissions as $allowedPermission) {
$regexrule .= '\b'.$allowedPermission.'\b';
if(end(self::$allowedPermissions) !== $allowedPermission) $regexrule .='|';
}
$regexrule .= "/";
return 'regex:'.$regexrule;
It is adding backslashes where I don't expect them:
regex:\/\\buser_add\\b|\\buser_edit\\b|\\buser_delete\\b|\\buser_view\\b|\\bpatient_add\\b|\\bpatient_edit\\b|\\bpatient_delete\\b|\\bpatient_view\\b|\\bmake_per\\b|\\bmake_per_withconfirmation\\b|\\bconfirm_per\\b|\\beval_per\\b|\\beval_per_withconfirmation\\b|\\bconfirm_per_report\\b\/
Backup screenshot of regex
Is there a workaround?
I found out that returning it in json format was adding the backslashes.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want replace php codes in string and running fro server
$x = 1;
$string = "OK:{first}Yes{second}No";
I want replace if($x == 1){ to {first} and } else { to {second}
After run and echo $string , I want result in html :
OK:Yes
How did you come up with this approach? Why not simply:
$string = $x == 1 ? 'OK:Yes' : 'OK:No';
That would get you the string you want based on the value of $x.
Also if you literally mean that you want to do a search-n-replace on the PHP code itself (as #OllyTenerife assumes), then are you going to write it into a file to be executed later, or use eval() or something? Doesn't sound like the right track there... In which case, remodel your code.
$string = str_replace("{first}","if($x == 1)",$string);
$string = str_replace("{second}","} else {",$string);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can i loop through string of phone number and remove the leading zero and replace with country code?
Example:
I want to replace each leading zero (0) of the phone numbers with "233";
$pn_box='08064342060,08052031697,08064342060';
Though I tried doing it this way but it converts only the first phone number
echo $newNumber = preg_replace('/^0?/', '+'.'233', $pn_num);
Output:
$pn_box='+2338064342060,2338052031697,2338064456763';
Thanks in advance
<?php
$pn_box='08064342060,08052031697,08064342060';
$new_pn_box = array();
$tempArray = explode(',',$pn_box);
foreach($tempArray as $phone_number) {
$new_pn_box[]='233'.substr($phone_number, 1);
}
$new_pn_box = implode(',',$new_pn_box);
echo $new_pn_box;
This will only replace the first 0 of each phone number with '233'.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have html code loaded in array $gh[0] and i am coonverting it to plain text
if i compare with same text loaded into new variable it doesn't works
can someone help with the issue, what should be exact value in $a to match the content in $gh[0]
i want comparsion to be working , what will be output if $gh[0] is converted into plain text especially line break
<?php
$gh[0]="Net inventory (used in)/from<br>Production Activities"
$fg=$gh[0]->plaintext;
$a="Net inventory (used in)/from Production Activities"
if($a == $fg)
{
echo "match";
}
else
{
echo "No match";
}
?>
What about just stripping all elements from the input?
$gh[0]= strip_tags($gh[0]);
If you want to know what the value (of $fg) is, why don't you check it?
There's echo, print_r and var_dump.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I don't know exactly how to say this, I'll use an example.
//[$var:Username|n] will print username with n length
$myText = 'The participants are [$var:Username|10], [$var:Username|8], and [$var:Username|6]';
$username = array('Alexandrite', 'Maximillian', 'Angelina');
$result = someFunction('[$var:Username|n]', $username, $myText);
echo $result;
//The participants are Alexandrit, Maximill, and Angeli
Any idea how to do this? Maybe using preg_replace?
I'm interested to know why you would even need to do this. Regardless:
preg_replace_callback('/\[\$var:Username\|(\d+)\]/', function ($match)
use (&$count, $username
) {
return substr($username[$count++], 0, $match[1]);
}, $myText);