Converting to HTML, from form POST, etc

See here

Converting String To Variable

You don’t need to, but if you want to force to a particular type you can:

  $DeviceId = intval($DeviceId);

Converting Variables To String

No need, PHP automatically converts a varaible to the type needed for the context being used

  $number = 12345 & 67890;   //$number is used as a numeric varaible
  echo substr ($number, 3, 1);   //$number is used as a string

Convert copy and pasted text

  //Convert copy and pasted email addresses (seperate email addreses by comma or newline or both)
  $emails = preg_split("/[\r\n,]+/", $email_addresses, -1, PREG_SPLIT_NO_EMPTY);

Remove special characters from a string

  //Remove all special characters
  $MyString = str_replace(' ', '-', MyString);                  //Replaces all spaces with hyphens.
  $MyString = preg_replace('/[^A-Za-z0-9\-]/', '', $MyString);  //Remove all special characters
  
  //This string: 'a|"bc!@£de^&$f g'
  //Will become: 'abcdef-g'
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *