I am unclear how to apply one function to another here.
I tried it in the switch with no results.
Also tried it directly in the other functions but I am just not getting it.

I have my ucfirst function

function change_tag($tag)
{
return ucfirst(strtolower($tag));
}
//print change_tag('HMM.'); 

switch

	  case "create":

		if (is_jpeg($_FILES['photo']['type']['file']) 
			  and is_valid_file_size($_FILES['photo']['size']['file'])
		   )
		{
    if(is_fields_filled_out($_POST['photo']))
	    {
			  $_POST['photo']['theme_id'] = $this_weeks_theme['id'];

				$photo_id = create_photo($_POST['photo']);
				copy($_FILES['photo']['tmp_name']['file'], './photos/original/'.$photo_id.'.jpg');
				 $notice = "Created photo";	
	    }


break;	

  }

and I want to use change_tag with these functions

	function create_photo($params)
	{
	   db_connect();

	 $query = sprintf("INSERT INTO photos set
		                             photos.title = '%s',
									 photos.email = '%s',
									 photos.discuss_url = '%s',
									 photos.theme_id = '%s',
									 photos.fullname = '%s',
									 created_at = NOW()",
									 mysql_real_escape_string($params['title']),
									 mysql_real_escape_string($params['email']),
									 mysql_real_escape_string($params['discuss_url']),
									 mysql_real_escape_string($params['theme_id']),
									 mysql_real_escape_string($params['fullname'])
									 );

	 $result = mysql_query($query);

	 if(!$result)
	 {
		  return false;
	 }

	 $photo_id = mysql_insert_id();

	 create_photo_tags($params['tags'], $photo_id);

	 return $photo_id;
}	



/**
 * creates our tags for our photos
 * @param string $tag_str
 * @param int $id
 * @return bool
 */
function create_photo_tags($tag_str, $id)
{
  db_connect();

	$tags = explode(',', $tag_str);

	foreach($tags as $tag)
	{
		 $not_empty = trim($tag);
		 if(!empty($not_empty))
		 {
		 $query = sprintf("SELECT id from tags WHERE name = '%s'",
			                                   mysql_real_escape_string(strip_tags(trim($tag)))
			                                   );
		  $result = mysql_query($query);
			if(!$result)
			{
				  false;
		  }
			$num_rows = mysql_num_rows($result);

			if($num_rows > 0)
			{
			  $tag_id = mysql_result($result, 0, 'id');
			}
			else
			{
			  $query = sprintf("INSERT into tags set name = '%s'",
			                                   mysql_real_escape_string(strip_tags(trim($tag)))
			                                   );
		    $result = mysql_query($query);
			  if(!$result)
				{
				  false;
				}
			  $tag_id = mysql_insert_id();
			}

			  $query = sprintf("INSERT into taggings set photo_id = '%s', tag_id = '%s'",
			                                    mysql_real_escape_string($id),
												mysql_real_escape_string($tag_id)
			                                   );
		    $result = mysql_query($query);
   }
	}

	return true;

}

    and I want to use change_tag with these functions

    where??

      I want to use it on all tags inserted into the database.

        $tag=change_tag($tag);
        

        should be sufficient

          dagon;10967791 wrote:
          $tag=change_tag($tag);
          

          should be sufficient

          Hey dagon,

          Thanks for the reply.

          I thought it would be as you stated. I had placed

          $tag=change_tag($tag);
          

          before my post ... in the controller which is working with all my other functions but I didn't get the ucfirst to work. I placed it above and below the copy($_FILES .....
          which made scene to me since I am calling other functions there which place photo data into the DB.

          I also placed it at the beginning of the other two functions. So I thought I'd ask for some assistance.

          Right now all my functions are in db_fns.php which is an include at the top of index.php and index.php is my controller at the moment.

            need to see the code your using.

              4 days later
              dagon;10967846 wrote:

              need to see the code your using.

              Thanks Dagon

              What additional code would you need to see other than the functions and switch I posted in my 1st post?

                If I'm understanding the question correctly, all you should need to do is run the function being called through your change_tag() function, e.g.:

                $result = change_tag(your_function($function, $params));
                
                  NogDog;10968153 wrote:

                  If I'm understanding the question correctly, all you should need to do is run the function being called through your change_tag() function, e.g.:

                  $result = change_tag(your_function($function, $params));
                  

                  Hey NogDog

                  Thanks

                  Using

                  $tag = change_tag($tag);
                  

                  at the beginning

                          foreach($tags as $tag)
                          { 
                          $tag = change_tag($tag);
                  

                  works

                  Yet I'd like to use an ucfirst function in my controller switch rather than inserting it in to each function that has string input posted.

                    Afraid I'm not seeing what the question/issue is. 😕

                    Once the function has been defined, you should be able to use it anywhere you want in your code. Or, I'm completely misunderstanding what you are asking?

                      you could use array_walk in the case 'section' to apply it to $_POST['photo'], but there's no real benefit

                        dagon;10968250 wrote:

                        you could use array_walk in the case 'section' to apply it to $_POST['photo'], but there's no real benefit

                        Thanks 🙂

                        I read http://php.net/manual/en/function.array-walk.php

                        If you have time would you post how I'd write and use that code?

                        as I said ... I am unclear how to apply one function to another here.

                        using

                                foreach($tags as $tag)
                                {
                                $tag = change_tag($tag); 
                        

                        will only upper case my first tag in the array.

                        array_walk may upper case each tag word.

                          emetib;10968268 wrote:

                          using

                                  foreach($tags as $tag)
                                  {
                                  $tag = change_tag($tag); 
                          

                          will only upper case my first tag in the array.

                          no it applies it to each $tag

                            Seems like some sort of question of scope. If all your functions are in an external file, I'd try to validate that the external file will parse correctly. This is easily done if you have command line PHP ability:

                            $ php -l db_fns.php
                            No syntax errors in db_fns.php

                            You might also try wrapping your code in a conditional test that uses [man]function_exists[/man] with an appropriate error handler:

                            <?php
                            
                            if (!function_exists("change_tags")) {
                               die("Change tags isn't a valid function here at line #");  // put your line # in there
                            } else {
                               // do your processing
                            }
                              Write a Reply...