منتدى مصر التقني
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

مساعدة في سؤال بلغة php

اذهب الى الأسفل

مساعدة في سؤال بلغة php  Empty مساعدة في سؤال بلغة php

مُساهمة من طرف ميرال احمد الخميس مارس 17, 2022 7:40 pm

السلام عليكم ورحمة الله وبركاته .
اريد المساعدة في هذا السؤال بلغة php ومشكورين سلفا 

Create a class name it friendContInfo with 4 properties with 
there setters and getters

 One of the properties is the phone which have to be 
validate (define an utility method for this task). 


• Any object of friendContInfo should be
 initialized 
automatically at creation time

• Add a Destructor to friendContInfo 


• Add members to friendContInfo for counting the number 
of object of the class has been created
ميرال احمد
ميرال احمد
.
.

تاريخ التسجيل : 17/03/2022
المساهمات : 2
النقاط : 7
التقيم : 1
الدولة : لبنان
الجنس : انثى

الرجوع الى أعلى الصفحة اذهب الى الأسفل

مساعدة في سؤال بلغة php  Empty رد: مساعدة في سؤال بلغة php

مُساهمة من طرف السنى الخميس مارس 17, 2022 10:28 pm


الحل

الكود:
<?php
// Define a class
class frindContInfo {

  // Declaring 4 private varaibles
    private $id;
    private $firstName;
    private $lastName;
    private $Phone;
   
    // Declarte construct method which accepts 4 parameters
    public function __construct($id, $firstName, $lastName,$Phone)
    {
        $this->id = $id;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->Phone = $Phone;
     
     
    }
   
        public function setID($id){
        $this->id = $id;
      }
      public function getID(){
        return $this->id;
      }
   
      public function setFirstName($name){
        $this->firstName = $name;
      }
      public function getFirstName(){
        return $this->firstName;
      }
     
      public function setLastName($name){
        $this->lastName = $name;
      }
      public function getLastName(){
        return $this->lastName;
      }
     
    // Declare a method for set phone
    public function setPhone($phone){
   
        $this-> phone = $phone;
       
      }

      public function getphone(){
        return $this->phone;
      }
     
    // Declare a method for validate phone
      function validate_phone_number($phone)
  {
    // Allow +, - and . in phone number
    $filtered_phone_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
    // Remove "-" from number
    $phone_to_check = str_replace("-", "", $filtered_phone_number);

    // Check the lenght of number
    // This can be customized if you want phone number from a specific country
    if (strlen($phone_to_check) < 10 || strlen($phone_to_check) > 14) {
        return false;
    } else {
      return true;
    }
  }
   
      // Declare a __destruct() function.
    function __destruct()
    {
       
        if ($this->validate_phone_number($this->Phone) == true) {
        echo $this->id;
        echo $this->firstName;
        echo $this->lastName;
        echo $this->Phone;
        } else {
        echo "Invalid phone number";
        }
       
   
    }
   
 }

// Create a new object and  initialized it
$object = new frindContInfo('10','ahmed','elsony','00-972-598-195-871');


?>
السنى
السنى
........
........

تاريخ التسجيل : 18/02/2011
المساهمات : 249
النقاط : 464
التقيم : 25
الجنس : ذكر

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

ََ

مواضيع ذات صلة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى