2019年2月26日 星期二

Bootstrap Content




1. glyphicon (圖示)


  <a href="#" class="btn btn-info btn-lg">
          <span class="glyphicon glyphicon-asterisk"></span> Asterisk
        </a>

ref 1

2019年2月25日 星期一

jquery 1.X Function

Online edit: https://playcode.io/online-javascript-editor

0. JS syntax

Variable

declare:  var  message = ""; 


Array: 

var data1 = {"id":1, "system": "abc", "name": "andy"}
data1.length




Exception:


  try { 
    if(x == "")  throw "empty";
    if(isNaN(x)) throw "not a number";
    x = Number(x);
    if(x < 5)  throw "too low";
    if(x > 10)   throw "too high";
  }
  catch(err) {
    message.innerHTML = "Input is " + err;
  }

1. How to post data 

$.ajax({
 type: 'POST',
 url: url,
 data: data,
 dataType: dataType,
 success: function(response) {...},
 error: function(jqXHR, textStatus, errorThrown) {...},
});

  $.post("demo_test_post.asp",
    {
      name: "Donald Duck111",
      city: "Duckburg"
    },
    function(data,status){
      alert("Data: " + data + "\nStatus: " + status);
    });
  });



ref 1 2




2. Get/Set Form data

function: $("#id").val("contnet")




3. Parse Json

1. Simple parse
var parsedJson = $.parseJSON(jsonToBeParsed);
ref 1

2. Check string is json

function IsJsonString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}

4.  Button Cancel / close

https://stackoverflow.com/questions/6445946/display-yes-and-no-buttons-instead-of-ok-and-cancel-in-confirm-box


5.  Div auto 

1<div style="width:300px;height:250px;overflow:auto;">
2您要輸入的內容
3</div>





6.  Replace the word

function convert(str)
{
  str = str.replace(/&/g, "&amp;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/"/g, "&quot;");
  str = str.replace(/'/g, "&#039;");
  return str;
}

7.  Jquery Add and remove class

1
$( "p" ).removeClass( "myClass noClass" ).addClass( "yourClass" );


ref 1


8. JS undefined check

if (typeof(myVariable) != "undefined")
Or
if (myVariable) //This throws an error if undefined. Should this be in Try/Catch?
ref 1


9.  How to set number

var nf = new Intl.NumberFormat();
nf.format(number); // "1,234,567,890"

11. Set object

1

var object = {
  foo: 1,
  "bar": "some string",
  baz: {
  }
};


12.  function
1


13.  javascript regular

console.log(/^.+\/\d+,.+$/.test('1abc/24,abc'))
var myString = "something format_abc";
var arr = myString.match(/\bformat_(.*?)\b/);
console.log(arr[0] + " " + arr[1]);
ref 1 2

2019年2月21日 星期四

PHP 5 Function


1.  GET NETWORK parameter

$_POST, $_GET, $REQUEST

content:
exampel: $_GET['name']



ref:  1 2 3


2. isset() 

Content: check variable is set
ex:    isset($_GET['action'])


3.  print_r($array,  true)

parameter: true, meaning not output to stdout
content: output $array content
ex:   error_log(print_r($array, true))


ref: 1


4.  htmlentities

content: change special word  to the htmlspecail word


<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

ref 1


5. pcntl_fork



ref 1 2 3 4 5



6.  Reflect class

----

 class ClassOne
{
    protected $arg1;
    protected $arg2;

    //Contructor
    public function __construct($arg1, $arg2)
    {
        $this->arg1 = $arg1;
        $this->arg2 = $arg2;
    }

    public function echoArgOne()
    {
        echo $this->arg1;
    }

}

$str = "One";
$className = "Class".$str;
$class = new \ReflectionClass($className);
$instance = $class->newInstanceArgs(array("Banana", "Apple"));
$instance->echoArgOne();
---------



7.  Array Function pass by


<?php
        //Enter your code here, enjoy!

$array = array("1" => "PHP code tester Sandbox Online",
              "foo" => "bar", 5 , 5 => 89009,
              "case" => "Random Stuff: " . rand(100,999),
              "PHP Version" => phpversion()
              );
           
assignEmpty($array, "ipo");

function assignEmpty($array, $field)
{
    $array[$field] = 100;
 
}

$array["ipb"] = 77;

print_r($array);


8.  PHP Redirect



if (/*Condition to redirect*/){
  //You need to redirect
  header("Location: http://www.yourwebsite.com/user.php"); /* Redirect browser */
  exit();
 }
else{
  // do some
}

9. PHP html add the code

in .htaccess
AddType application/x-httpd-php .html .htm

ref 1


9 PHP auth


https://www.php.net/manual/en/features.http-auth.php


ref
http://ms7.fhsh.tp.edu.tw/php5c/features.http-auth.html


10. php varaible request

https://stackoverflow.com/questions/520132/does-static-variables-in-php-persist-across-the-requests

https://softwareengineering.stackexchange.com/questions/276512/is-this-a-race-condition




10 PHP stdclass and array change 

$query = new stdClass();
$query->age = 10;
$query->name = "andy";

echo $query->{"age"};
echo $query->{"name"};
/////////////////////////
$qArray = (array) $query;
echo $qArray{"age"};
echo $qArray{"name"};