Jump to content

Recommended Posts

Hi guys, i have 2 questions that i hope someone will help me on. Because its killing me, i can't solve it.

 

 

 

 

 

1) Write a function that will convert an array of lower case strings passed by reference into an array of upper case strings

 

 

 

e.g function convert(&$array_strings){

 

            //insert code

 

}

 

 

 

I tried this:

 

function convert(&$array_strings)

{

    $array_strings="hello this is php coding in lower case to upper case";

    $higher=strtoupper($array_strings);

    print("$higher");

}

 

 

 

 

 

2)Using regular expressions generate a function that will check if a filename stored in a string is of the correct format. The function should return a Boolean result. Any 1 upper case letter, followed by 3 lowercase letters, followed by any digit, followed by a .php or .PHP file

 

eg. Gone8.php

 

 

 

I tried this:

 

function regular_expressions($boolean)

{

    if(preg_match("/[A-Z]{1}[a-z]{3}[0-9][.]p[Hh]p/","Gone8.php"))

      {

          return 1;

            if ($boolean == 1)

              {

                  print("true<br/>");

              } 

            return false;

      }

     

 

 

 

Extra: what happens if you try "Gone8.phpProblem" Does it return true or false? Can anyone fix the problem if there is one?"  --->Can anyone explain the answer and rationale behind it to me ?

 

 

 

Many thanks!

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/133755-any-help-on-this/
Share on other sites


anyway....

try to solve pretty small things by yourself,  that may teach u a lot...

function convert(&$array_strings)
{
    
    $higher=strtoupper($array_strings);
    print($higher);
}$array_strings="hello this is php coding in lower case to upper case";
convert($array_strings);




2.


function regular_expressions($boolean)
{ 
    if(!preg_match("/[A-Z]{1}[a-z]{3}[0-9][.]p[Hh]p/",$boolean))
      { 
           
            return false;
                 
              
           
      }
  
  else {
  
   print("true<br/>");
  
  } 
  }
      $qqq="Gone8.phpProblem" ;
  regular_expressions($qqq);

Link to comment
https://forums.phpfreaks.com/topic/133755-any-help-on-this/#findComment-696063
Share on other sites

<?php

$stringArray = array( 'Lorem',
                      'ipsum',
                      'dolor',
                      'sit',
                      'amet'
                    );
echo '<pre>';
print_r($stringArray);
echo '</pre>';

$stringArray = array_map('strtoupper',$stringArray);

echo '<pre>';
print_r($stringArray);
echo '</pre>';

?>

Link to comment
https://forums.phpfreaks.com/topic/133755-any-help-on-this/#findComment-696120
Share on other sites

I'm pretty sure we don't answer HW problems here.. but I may be mistaken.

 

We recently decided it's not our duty to be the little angel sitting on people's shoulder.  If someone wants to try and get someone to do their homework for them in a class that is probably most likely voluntary in the first place, that's their prerogative.  And if someone wants to come along and "help" the guy (I do use quotes because frankly, I do not think they are helping him at all), that's on them, as well.  Anyways, point is, we're not babysitters or parents.  We think it's retarded and stupid for someone to voluntarily take a class only to turn around and ask for other people to do the work, and even more retarded and stupid when people actually help them, but hey, that's the double edged sword of freedom of choice. 

 

 

Link to comment
https://forums.phpfreaks.com/topic/133755-any-help-on-this/#findComment-696166
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.