Finding @ In A String, And Other Items
Ok - I want to check a string for @ in it (Im checking to see if a string
that should contain an email holds a @ )
How would I go about this? preg_match? ereg? strstr? Examples?
Also - how would I find any non alpha numeric characters in a string so I
can give the user an error message. I dont want any characters besides
alpha-numeric in the strings.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Create String With Checkbox Items
I'm creating a php script to interface with a database that will contain work requests for my office. Each job needs to be assigned to a person, possibly more than one person. The database field for this is named 'assigned_to' and will contain some data similar to "dave, randy, scott" for people who worked on the job. Does that sound reasonable? Code:
Finding A Value Within A String
Say I have a string, for example: "Name: bob, Age: 22". I know that there is a name stored in there and that it is in that format. How can I trim that string down until it's left with just the name?
Finding A Space In A String
I am trying to find a space in a string. If I have a sentence like: This is a sentence. I would like to be able to find the second space form the endand then return that part of the sentence, so if I ran it on that sentnece above it would return "a sentence.", but I won't know what the sentence is.
Finding And Extracting From A String
Heres the situation: I got a file with lines like: name:second_name:somenumber:otherinfo etc with different values between colons ( just like passwd file) What I want is to extract some part of it like all names or numbers from each line, simply text fom between e.g. second and third colon. And turn it into array so that I can later operate on these strings. And second, variation of it: To get whole lines that contain some characters like 3 digits from a number second b) :) to extract only nmbers with some digits not whole lines.
Finding Spaces In A String
I am now looking for a way to go through a string variable, find any space that is present and replace it with _. How would I go about? The reason is I get input from a user.. lets say he/she loads a variable $Hockey = "Edmonton Oilers"; this variable is used to create a new webpage but of course, the web does not like spaces.. hence I would need this variable to be $Hockey = "Edmonton_Oilers";
Finding Number In A String Of Numbers
I have a string of numbers separated by comma ',', eg $str = "1, 3, 56, 8, 9, "; (there's a comma at the end, because it was easier for me to do so) I need to compare a number ($id) if it's in the string. At first I thought, that strpos() will do the trick, but then it struck me, that 6 will be found (because of 56, ).
Problem Finding Occurances Of One String Within Another
Can anybody see what is wrong with this code? apparently i have an 'empty delimiter' on the line that sets $pos - can anybody see what is wrong with it? $search_for = $_GET['for']; $the_items_description = $row ["description"]; $pos = stristr($the_items_description, $search_for); if ($search_for == "") { $does_contain_text = true; } elseif ($pos === false) { $does_contain_text = false; } else { $does_contain_text = true; } // end text search if ($does_contain_text == true) { // rest of page works fine
Finding The Longest Word In A String
Is there a php function to find the longest word in a word list or sentence? I've got a massive list so if there isn't a function how would be the most efficient way of doing it? I've looked at playing with arrays but can't seem to find a quick and easy way...
StrPos - Finding Substring Within A String
I just wanted to know how to find every occurrence of a sub-string in a string? I would like to find the positions of every occurrence of a word within a sentence. CodingForums is a web code and development forum In the above sentence, I would like to have an array with the positions of all occurences of the letters "or" (2 occurrences in this case). I'm sure strpos can do this, can any one provide a function or the code necessary to do this?
Form Validation - Finding Duplicates: Regular Expressions Or String Functions?
I'm trying to figure out the most efficient method for taking the first character in a string (which will be a number), and use it as a variable to check to see if the other numbers in the string match that first number. I'm using this code for form validation of a telephone number. Previous records from the past few months show that when someone is just messing around on one of our forms (to waste our time), they type in a phone number like "555-555-5555" or "111-222-3333". Our Web forms have three text boxes for each telephone number: homephone1 = area code (3 digits) homephone2 = prefix (3 digits) homephone3 = suffix (4 digits) businessphone1 = area code (3 digits) businessphone2 = prefix (3 digits) businessphone3 = suffix (4 digits) My plan is to check for this pattern, then if I find it, just redirect the user to the thank you page so they'll think the form was processed, when it actually wasn't. As we find additional patterns that people use for malicious data, I'll enter those as well (e.g., 123-123-1234) Also, if you see any tutorials, or articles that talk about "real world" form validation please point me to them. I've been looking for references for form-based validation logic that takes real world dummy data into account, but haven't found much.
Related Items
I noticed a lot of websites show "Related Items" on each product page. I want to know how usually do you implement it. Should I add a field in the mysql table to hold the "Related Items" information? What's the best solution?
Get ID Of Deleted Items
I wonder if there is anything similar to "mysql_insert_id();" for deleted/updated id's? If i do a query and DELETE WHERE text_field="", can i get the id's of the fields that were deleted?
How Many Items Are In An Array?
I dont know how many values there are in my array after it's been split.. is there a command? array_count_values doesnt do what I need sadly.
Add/Delete Items
I have the following code, that displays a message whether a users shopping cart contains items or not. How do I add/delete items from the shopping cart, upon the appropriate product link being clicked? If a items is already in the cart, how do I display a message notifying the user? Code:
Favorit Items
i have many tables with different data structure due, am making a service which will allow users to add itimes to thier "favorit items" tables I thinked to use the table names as a hidden filed, like if the table name is "hotel" and the user added a hotel to his favorit items , the hidden fild will be hotels, and then pass that field as a variable then use it in a query to get the hitel data, does this adea work? or there is a better way ?
Using If Empty With Two Items
I am trying to say if $_Post and $_Session are empty set the variable $dcparent to equal 1, but it doesn't like what I am doing. if(isset($_POST['dcparent'])) { $dcparent = mysql_real_escape_string($_POST['dcparent']); } if(isset($_SESSION['dcparent'])) { $dcparent = mysql_real_escape_string($_SESSION['dcparent']); } if(empty($_POST['dcparent']) && (empty($_SESSION['dcparent'])) { $dcparent = 1; }
Multiple Cart Items
I've created a shopping cart application using php 4.06 and postgres. a problem i had was that when i added the same item twice it was adding an extra item as opposed to adding the quantities together. i did manage to sort this out to an extent but my only solution means using a block of code for each item which has made my script very long and i'm pretty sure has made the script somewhat unreliable. I would appreciate it greatly if someone could offer a solution to this, this is my code for adding items to the cart: PHP Code:
Multiple Items Of Same Name In Session?
I have a shopping cart where I can add tshirt designs to the cart. The designs are added to a php session object called cart. The object 'cart' consists of the design name, color and the quantity. The probem is that if someone adds the same design to the cart again then it just increments the quantity of the existing design with the same name instead of adding another instance of it to the cart. How can I have multiple instances of the same design with the same name in the cart at the same time. One thing I thought of was to append some sort of incrementing id to the design name before it is added to the cart. Thus the next time the design is added it would have a new id appended and the resulting name would be different.
Dynamic Form Items
I am trying to create A form that its fields will depend on a form menu. for example. /***********************************************/ <form name="form1" method="post" action=""> <select name="select"> <option value="1">option 1</option> <option value="2">option 2</option> <option value="3">option 3</option> </select> Text field 1<input type="text" name="textfield"> Text Field 2<input type="text" name="textfield2"> Text Field 3 <input type="text" name="textfield3"> Text Field 4 <input type="text" name="textfield4"> <input type="submit" name="Submit" value="Submit"> </form> /***********************************************/ When the option 1 is selected only the textfields 1 and 2 to appear, when option 2 is selected only textfields 1 and 3 to appear and so on... any combination I would like. I tried puting the textfields in "if" statments but i don't like it. its too messy PHP and HTML code. Any Ideas of how this could be done better ? If someone did something similar before and has a relative link it would be good as well.
Number Of Items In A Cart
I am working with a session and a 'cart' (note that I do not really know what I am doing though). I was wondering if there is some easy way (function) to work out how many items I have in my 'basket' / 'cart', because then I could call this function from anywhere to show the user just how many items are on order
Only Allow X Number Of Items To Be Checked
I have a function that renders out tag categories, and then all the tags within said category. Each tag has a checbox beside it, i am wondering if it's possible to only allow a user to check 4 tags. Here is the function: Code:
Display Items Using Checkbox
i have a page where in it lists all job items on a table and each item has a checkbox so when i check one or more items when i click the post button it should display the job items on this post page. my problem is, my post page is not working. Code:
Count Of How Many Items Are In Database
I am wanting to create an select menu for displaying the order of the item on a page. I am guessing that I need to get the count of how many items are in the db and them put them into a select menu. Does anyone know how to do this or can point me in the right direction?
Display All Array Items
How do I display all the items within an array? Also, how do I delete a particular item from an array?
Changing Items After A Date
What I have is a table (code below) and it is for an events page. What I want is after the date has gone, it changes the whole row to grey. ( #666666 ). Code:
Deleting Items From A List
When i click one of the delete buttons, the form submits, but nothing happens. I'm pretty sure i'm doing something stupid with the form buttons, but I've been staring at it too long...any takers? Code:
Multiple Items In Foreach()
Can someone tell me what im doing wrong with the code bellow please? I get print_ticket called lots of times, with 1 as the hash,name,ticket_no responce. (i have chequed that the query is returning the right results). $return = pg_query($pg_connection, $query); $data = pg_fetch_array($return); foreach ( $data as $temp ) { echo print_ticket ($temp['hash'],$temp['name'],$temp['ticket_no']); }
Compare Items In An Array...
I have been getting on fine with basic coding until I stumbled accross a problem. I cant seem to figure out how to check to see if a value in one array is in another array - and if so just simple report back "true" or "false". Lets call the two arrays LOCKS and KEYS. Doing a print_r($locks) would give: Code:
Seperating Search Items
When conducting a php sql search i get some great results, however i want to expand my results so that when multiple search terms are added it will display all relevant fields. $query = "SELECT * FROM Mixes WHERE dj LIKE '%$var%' OR event LIKE '%$var%' OR tracklist LIKE '%$var%' OR date LIKE '%$var%' ORDER BY event ASC"; From the above search i can only get single results from 1 field. I want to be able to seperate the search term into individual items that can be referrenced in the database. So for example i search for a dj name and also an event they play at i get zero results, however if i search for them individually i get the results i want. How do i expand the code to display the result of both the dj and the event or any of the other fields? I presume that i need to be able to set each search item into an individual variable and then use them to search.
How Do I Delete Items From Array?
I can add several items to the basket, but how do I delete one from the basket? I want to delete any of the added items. Here is my code for creating the array and adding items to it. // creating the array $item = array(); $item['id'] = "1"; $item['price'] = "100"; $item['quantity'] = "1"; // add item $_SESSION['basket'][] = $item;
Adding Items To A List Or Menu
Not sure if it is a php question but since i am working in php here it is. Ho can i add items to (the item label=visual text and the value=index number) a list object on a website. I am having a list with 4 items and i would like to add the text from a textfield (textfield1.value) to the list object so it will hold 5 items.
Dynamic List Items Repeating Themselves
I'm working on this online magazine, and each page (well, other than the front page) has a menu included on the right-hand side consisting of articles divided into three sections: articles, columns, reviews. For some reason, whenever I click on one of these article links, that link takes the place of the first link in the section. You can see what I mean here: PHP for the included right_menu.php PHP Code:
Adding Only Unique Items To An Array
I've made a small code snippet that adds a new item ($value = $_GET) to an array in a cookie. My main question is in the title of the post, and I have a related one: How do I delete a specific value from the array and shift all the other values down to fill its place? Will this happen on its own? And one more: Using this code I display the array values in descending order; foreach ($_COOKIE['best'] as $name => $value) { $best = urlencode($value); echo //insert code here } } Is there any way to display this in ascending order?
Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned: [connect] $sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5"; $result = mysql_query($sql); while($cards = mysql_fetch_array($result)) { $value = $cards["card_value"]; $suit = $cards["card_suit"]; $image = $cards["card_image"]; -------- Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this: $spades = 0; if($suit='spades') { $spades = $spades+1; } and I tried a foreach statement to count within the loop which always returns a count of 1. Would someone be so kind as to point me in the right direction?
Adding List Items To A Database
Not sure if this is javascript or php so i put it in both newsgroups, sorry if it's the wrong group. I wrote (with help) a code to put several items in a list object (select) and I would like to add the items in this list to a database. I know how to add a selected item to the database but how can i put al the items tot the database. I need somekind of loop wich go's through the list.
Count Number Of Items In Each Category
I'm trying to list my categories and how many items are in each category. I'm not much on sub queries. How can I combine these two items. I'd like to display the category and the corresponding number of items in each ....
How To Pull Only Unique Items From Database?
I have a table like this: date, author, title, content now I want to grab the 3 latest items from this table from 3 DIFFERENT authors. I want this: -article by jim -article by sally -article by john Not this: -article by jim -article by jim -article by sally even if the two latest articles happen to be by jim, lets only grab the first one and move on. So basically I need (in pseudo-sql/plaintext): select title from contenttable where author=unique order by date limit 3 I've got everything code-wise except the "author=unique" part, how do I do that?
Seperator Instead Of A Comma For Listed Items In DB?
I'm making a recipe database, and need to have DB fields in mySQL that will have lists of values that would get sent to an array to be worked on. I anticipate that at times a comma will need to be used in the value itself. So, what's a commonly used symbol or something that people tend to use as a separator of a list that would then be used in the split() function to send the elements into an array?
Print All Selected Items From Dropdown??
I have a program that allows users to select a 'New Graduate' membership, and for each one selected, they get a free tshirt. I've got that working using a 'is_new_grad' function that I created. So, if they select 2, they see 2 dropdowns to select the sizes of them. It then sends an email w/ the membership info and the shirt sizes selected. However, when the email is being sent, it's only returning the size of the LAST item selected in from the drop-downs. Example: if I sign up for four of these memberships and select four different tshirt sizes (1 Medium, 1 Lg, 1 XL, and 1 XXL), the info in the email is all XXL: Code:
Updating Multiple Items With One Form
I am using a do while loop to run through a list of items on my page. Say I have 5 items on the page and each has one field that the user can input information to. Is there a way to do an update where it will update all records on the page with one submit form?
Displaying Multiple Items From Database
what i have is a page that has four sections. what i want to have is when the page opens, in that page i want the lastest two items for each section from a database to be displayed. the items to be displayed are an image, a title and a description. but i also want the description to be shortend to say about 25-30 words or about 100 chars, if thats easier? so in the end i have 4 sections, each showing the lastest two items for each section. would the best way to do this be to have a seperate table in the database for each of the sections? or would i be able to do it from one table? would i have to creat a query for each of the sections? e.g: SELECT * FROM table WHERE section=section
Unable To Remove Items From A File
I am at my wits end with some code for a website I am working on. The page in question is simply for a user to add items to a list of data. The data is stored in a temp file and later added to a database. I have successfull set the page to add items to the list of data. My issue is with trying to remove a line of data from the file. The following snippet of code runs if a link has been clicked on the line of data to be removed which reloads the page running this code which is intended to remove that line... PHP Code: ....
SSL Error Pop Up - Page Contains Both Secure And Nonsecure Items
I recently took over a site written in PHP. We utilize a third party to perform a job match, search, and application. When this page loads in IE, we get a pop up that says: The Page contains both secure and nonsecure items. Do you want to display the nonsecure items? How can I get rid of this as people going to fill this application out...
PHP Scripts To Diplay Items From XYZ Date Til Today
I'm trying to work out the SQL command script to display all items from a fixed time period til the current date. Something like... $sql_query = "SELECT * FROM mytable WHERE dateAdded like 'todays date - 60 days'";
|