Building a String using Concatenation and Ternary Operator


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $uri = '';
  2. $uri .= in_array('scheme', $parts) ? (!empty($this->_scheme) ? $this->_scheme.'://' : '') : '';
  3. $uri .= in_array('user', $parts) ? $this->_user : '';
  4. $uri .= in_array('pass', $parts) ? (!empty ($this->_pass) ? ':' : '') .$this->_pass. (!empty ($this->_user) ? '@' : '') : '';
  5. $uri .= in_array('host', $parts) ? $this->_host : '';
  6. $uri .= in_array('port', $parts) ? (!empty ($this->_port) ? ':' : '').$this->_port : '';
  7. $uri .= in_array('path', $parts) ? $this->_path : '';
  8. $uri .= in_array('query', $parts) ? (!empty ($query) ? '?'.$query : '') : '';
  9. $uri .= in_array('fragment', $parts)? (!empty ($this->_fragment) ? '#'.$this->_fragment : '') : '';

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.