Jump to content

Search the Community

Showing results for tags 'preg_replace'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 5 results

  1. So i'm not still really familiar with regex and how does it work, but i have issue with my code. I have ¤ in my text and it gets replace with unicode ? block. https://en.wikipedia.org/wiki/Specials_(Unicode_block) for me and I don't get why. Here is the code I'm using. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> #kool { width:800px; border:groove; margin:0 auto; padding:25px; } </style> </head> <body> <?php /* Test preg_replace function */ $preg_pattern = "/[^A-Za-z0-9!\"#%£&()=@\s]/"; if (isset($_GET['preg'])) { echo "<div id='kool'>"; echo "<b>Original string: </b> " . $_GET['preg']; echo "<hr>"; echo "<b>Preg pattern: </b> " . $preg_pattern; echo "<hr>"; echo "<b>Result: </b> " . preg_replace($preg_pattern,"",$_GET['preg']); echo "</div>"; } ?> <form method="get" action="preg_test.php"> <input type="text" name="preg" <?php if (isset($_GET['preg'])) { echo " value='" . $_GET['preg'] . "'"; } ?>> <input type="submit"> </form> </body> </html> And here is the string I'm trying to use. Test 0-9, Specialcharacters: !"#¤%&/()=? Result image below Any guides / help appreciated.
  2. Hi all, I have a problem for sanitizing / validating a web address input. My personal favor is doing it with regex. I made a simple example with preg_replace <?php if (!empty($_POST['wbddrss']) ) { $wbddrss = $_POST['wbddrss']; $wbddrss = trim($wbddrss); var_dump($wbddrss); $validate = preg_replace('/<>/' , '', $wbddrss); var_dump($validate); } ?> But I would like to replace all chars that do not meet what is allowed. I guess the best solution would be to replace everything with a caret to negate. But it seems I cant find the right delimiters. This is the range of characters I would like to allow: A-Za-z0-9+&@#/%?=~_|!:,.;\(\) how is this done in a preg_replace function?
  3. I want to use preg_replace to input only a-zAZ with a limit of 30 characters I have a piece of code I used before but it works with preg_match. example function: <?php // input form to get the name // use the function here $name = valid_name($name); // function to validate name input function valid_name($data){ $data = ltrim($data); $data = rtrim($data); $data = preg_replace("/^(?:[A-Za-z][A-Za-z\-]{2,30}[A-Za-z]|[A-Za-z])$/", '' , $data); return $data; } ?> To give an impression of how I use it; a part of the confirmation form <html> <form action="mypage.php" method="post"> <p><input type="text" name="name" value="<?php echo $name; ?>" STYLE="background-color: #708DCC; color: white; height: 20px; width: 200px; border: none; font-size: 14px;" readonly ></p> <!-- rest of the form --> </html> The problem is in the preg_replace part. an input with chars like: ^&$ etc is not replaced, how to do this? if anyone can help I would be really happy.
  4. There is an issue I have with creating a filter for the correct domain and toplevel domain. For example google.com is correct and all the other not. my code: function my_funct($data2) { $data2 = preg_replace('#(http://www.|http:|https:|ftp://www.|https://www./|//|www.|htp:|htt:|htp:/|htt:/|)# ' , '', $data2); return $data2; } but directories wil not be blocked like www.google.com/directory/page/page2 is there a way to use preg_replace and put only domain and toplevel domain in it? maybe it is possible to negate it, but he entire validation of pre_replace would be changed I assume.
  5. I'm looking for a way to block input in a text field occuring more than 5 times. For example aaaaaa is wrong but: A sentence having an input of a happening several times or even more is okay. above sentence has 7 inputs and shouldnt be blocked. What is the solution?
×
×
  • Create New...