PHP - Removing A Particular Character From A Variable
Hi all,
I need to remove any '-' character from a user input in a html form. How can I get rid of this character? e.g. $var = A-1DAS $var1 = strtolower($var); I need the output as 'a1das' Similar TutorialsHello, I am trying to find a character in my DB's. The DB has the data setup with +(number) & -(number) I want to try and find a way for PHP to seperate them into two so each one has the seperate colour's. i have tried preg_match, strstr & strpos but none of them seem to work. Can you as PHP Genius's help out? EDIT: Please Do Not Worry, I have fixed this. For people who were wondering: $new_variable = strstr($variable_to_check, "+"); if($new_variable == "") { do one you want } else { do what you want. } Thanks PHP Freaks Thanks, NoMansLand <form action="main.php?id=test.php" method="post"> <input name="name" type="text" /> <input name="submit" type="submit" value="Look Up" /> </form> <?php if(isset($_POST['submit'])) { $today = date("Y-m-d"); $pname = rawurlencode($_POST['name']); $xml_feed_url = 'http://api.eve-online.com/eve/CharacterID.xml.aspx?names='.$pname.''; The above works perfect until the user enters a character like ' to the box, how do I get it to pass the ' into the address? Thank you I need to remove some text from a php variable. right now $testv = <span id="sobi2Details_field_street">www.google.com</span> I need to remove the <span id="sobi2Details_field_street"> and the </span> so im left with $testv = www.google.com I know via firebug that the correct parameters were passed to my process page and the parameter being passed that in caused issues on the process page is $characterIDList. What's causing the issue is that its not inserting the value into the insert query. The rest of the insert query works fine. process page $characterIDs = explode(',', $_POST['characterIDList']); foreach($characterIDs as $itm){ $id = (int)$itm; } $defaultcharid = (int)$characterIDs[0]; $query = "INSERT INTO `handlers` (username, password, firstname, lastname, email, status_id, isadmin, default_character_id, creator_id, datecreated) VALUES ('$username','$password','$firstname','$lastname','$email','$status','$admin', '$defaultcharid', 1, NOW())"; All, I have a zip code and for example the zip code is 01101. How can I determine if the first character in this is a zero? Thanks in advance. Thanks to the advice of others on PHPFreaks, I have decided that allowing any character for certain fields on my "Add an Article" form. However, I still want to define a length between 2 and 100. How do I re-write my RegEx to accomplish this? Befo Code: [Select] // Check HTML Title. if (empty($trimmed['htmlTitle'])){ $errors['htmlTitle'] = 'Please enter an HTML Title.'; }else{ if (preg_match('#^[A-Z \'.-]{2,100}$#i', $trimmed['htmlTitle'])){ $htmlTitle = $trimmed['htmlTitle']; }else{ $errors['htmlTitle'] = 'HTML Title must be 2-100 characters (A-Z \' . -)'; } } Here is my best guess... After: Code: [Select] // Check HTML Title. if (empty($trimmed['htmlTitle'])){ $errors['htmlTitle'] = 'Please enter an HTML Title.'; }else{ if (preg_match('#^[.*]{2,100}$#i', $trimmed['htmlTitle'])){ $htmlTitle = $trimmed['htmlTitle']; }else{ $errors['htmlTitle'] = 'HTML Title must be 2-100 characters (A-Z \' . -)'; } } Debbie all i want is for when their is a _ to be replaced with a space so i tried these and neither worked Code: [Select] <?php $pmod = str_replace("_"," ",$p); $pmod = preg_replace("_"," ",$p); ?> so i was wondering if because this was in a while statement, is this the reason its not working, and if so how should i fix it (this is the while) Code: [Select] <?php while ($z <= $w){ $p = $multi[$z]; $pmod = str_replace("_"," ",$p); echo "<a href='tag.php?tag=$p'" . $p . ">" . $pmod . "</a> "; $z++; } ?> so if I have a a string of text or something like Code: [Select] http://www.yahoo.com/ajhsijd908340 I can use str_replace to remove "http://" but what can I use to remove the "ajhsijd908340" if every time it is a different set of characters? I have problem, there are users with "?" character in username, and their address to profile is /profile/username/. I have var: $username that is that username, now, how can i replace all that characters which cant open users profile.. I mean for "?" i need to put "%3F", how can i replace? I know with str_replace, but is there any other solution like htmlencode or something like that? :S Hey, I'm having an issue with using Wikipedia's OpenSearch API - it sometimes gives me characters in a unicode format: "\u00f1" and I would like to convert back into a correctly displayed format (in this case, n-tilde; spanish n). Any suggestions? Hi, does anybody know why I get a question mark inside a diamond shape where a pound sign should be when i retrieve data from a mysql database? I have tried using latin1_general_ci and utf8_general_ci and they both do the same, don't know whether that is anything to do with it or not? Any help would be greatly appreciated. HI all, something that keeps bothering me is that i do not fully understand the usefullness of the \n newline character. When i use for testing in a string it doesn't show the effect in my browser. Only when I press view source I can see that right after the \n character the code jumps down 1 line. Does anyone know how and when to use it? I have see it with the php mail function, but i don't really understand why they use it. If someone could enlighten me i would be very happy I got another problem. It is a counting characters. When I reload text from database, I want to count how many characters are in text. The problem is that I use the timymce, and there is a tags </p> and formats <span> and other formats. How can I count characters without those format, just pure characters entire text? I need a php code. And some plus - text is in utf8 coding in database with utf8 bin. Can someone help me with this. I think I need to use substr: how do I only echo out everything after the period ( ".") for example if I have "table.birthday" I want to echo: "birthday" I am terribly confused... I am trying to display the html body of a message pulled through imap. I thought that if I did this: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> in the html head, that everything would be pretty much figured out for me, but... When I look at the original message in gmail (prior to being pulled with imap), I get an ellipses(...), but once I display it in my browser, I get a black diamond question mark thingy... Help! I've tried all manners of conversion, but suspect I'm completely missing the boat here. Thanks Hi people! I have a form with a select list where options are populated from a table in my db.. the string format is like this -> car - branch (ex. toyota - japan so on..) when viewing the options it displays correctly with the "-" but when i tried submitting the form which will be inserted into the db the "- branch" gets cut off.. i think i need to encode it but i don't know how to do it.. thanks for any reply! I have a $string with this structure "word-word2 something-SECONDPART". I want to divide it to $string1 and $string2 by separating with the last "-". The point is that "-" exists in the first part, and I just want to make the second string after the last "-" |