简体   繁体   中英

Match first letter of directory

Let's say I have a class table. In the class table, there are many students with their pictures. In the first registration, I've registered the class and students with pictures. The pictures were put into a directory like classid_classname. Then, I change the class name. Now, I'm adding the student's picture. Now, the new picture can't be recognized because the class name has changed. The pic url will be set as classid_class(new)name. How can I match the first letter of the directory? This is my update code :

    $classID= $_POST["classID"];
    $className= $_POST["className"];
    $p1 = $_FILES['p1']['name'];
    $p2 = $_FILES['p2']['name'];
    $p3 = $_FILES['p3']['name'];


    $direct = $_POST["className"];
    $direct = strtolower($direct);
    $direct = str_replace(' ', '_', $direct);

    $tfish = $classID."_".$direct;  //the directory variable will have new name 
    because it can't be fetched if the directory has been changed many times//

    $file = "slider_imagesClass/".$tfish."/";
    $url = "/".$tfish."/";

How can I make the variable to match the first letter of the directory because the classID will not change?

PHP treats strings as arrays of characters. You can access the first character by using:

$direct[0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM