Posted By

sveggiani on 01/05/09


Tagged

strings evFunctions


Versions (?)

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


 / Published in: PHP
 

  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  

You need to login to post a comment.