evAddParamURL | adds a param to a given URL and returns the new URL


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



Copy this code and paste it in your HTML
  1. // name: evAddParamURL
  2. // version: v0.1
  3. // description: agrega (o reemplaza si existe) un parametro en una URL
  4.  
  5. function evAddParamURL( $url, $key, $value ) {
  6.  
  7. $url = preg_replace( '/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&' );
  8. $url = substr( $url, 0, -1 );
  9.  
  10. if ( strpos( $url, '?' ) === false ) {
  11. return ( $url . '?' . $key . '=' . $value );
  12. } else {
  13. return ( $url . '&' . $key . '=' . $value );
  14. }
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.