tailieunhanh - The php anthology 2nd edition 2007 - phần 4

PHP làm cho thông tin đường dẫn có sẵn trong $ _SERVER ['PATH_INFO'] cho AcceptPathInfo hoặc MultiViews giải pháp, và ['REQUEST_URI'] khi sử dụng mod_rewrite trong $ _SERVER. | 142 The PHP Anthology Simpo PDF Merge and Split Unregistered Version - http Handling Pretty URLs PHP makes the path information available in the _SERVER PATH_INFO for the AcceptPathInfo or MultiViews solutions and in _SERVER REQUEST_URI when using mod_rewrite. We can handle those paths using a simple PHP class that will extract the path information from the incoming request. We ll call the class RequestPath and give it a single private property parts to hold all the parts of our request URLs excerpt class RequestPath private parts array The actual path parsing happens in the __construct method which simply explodes the path on the forward slash character and then proceeds to handle the first two path elements as special cases before dealing with the key-value pairs that follow them. The first thing we do is grab the path and trim the trailing character if there is one excerpt public function __construct if isset _SERVER PATH_INFO path substr _SERVER PATH_INFO -1 substr _SERVER PATH_INFO 0 -1 _SERVER PATH_INFO else path substr _SERVER REQUEST_URI -1 substr _SERVER REQUEST_URI 0 -1 _SERVER REQUeSt_URI Next we split the path into an array on the character. The first element we ll consider to be the action the second we ll consider to be the type Forms Tables and Pretty URLs 143 Simpo PDF Merge and Split Unregistered Version - http excerpt bits explode substr path 1 parsed action array_shift bits parsed parsed action parsed type array_shift bits parsed parsed type The remaining elements we group into key-value pairs. If an odd number of elements remains we simply place the last element on the end of our key-value array excerpt parts_size sizeof bits if parts_size 2 0 parts_size - 1 for i 0 i parts_size i 2 parsed bits i bits i 1 parsed bits i 1 if sizeof bits 2 0 parsed array_pop bits Finally as the last step of our constructor method we assign our

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.