Attaching A String To A Normal Word Without Loosing The String
In my database I have content rows that are either called <contentname>_title or <contentname>_fulltext. now when someone clicks a link on the site it goes to index.php?action=<contentname> so I guess you see where im going..
when someone goes to such a section index.php sees $action is used and attaches it to _title and _fulltext, so u get: $action_fulltext.. basicly of cuz php now sees it as one string '$action_fulltext' and not '$action'_fulltext.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Attaching A Word Document
Guys, i have the following code i am using to attach files to an email. It works and does do the attaching, all MS Word documents i attach do not open as they are. Instead they open with unreadable text. Where could i be going wrong? When i change the file type to application/pdf and attach a pdf file, it opens well, just as it is.... <?php $name=$_POST["name"]; $reply_email=$_POST["reply_email"]; $sub=$_POST["subject"]; $attach_file=$_POST["attach_file"]; $sender=$_POST["sender_email"]; $reciever=$_POST["reciever"]; $message_to_send=$_POST["message"]; $multi_receivers=$_POST["bcc_receivers"]; if((empty($name)¦¦empty($reply_email)¦¦empty($sub)¦¦empty($reciever)¦¦ empty($message_to_send)¦¦empty($multi_receivers))){ header("Location:empty.php");} elseif($attach_file=="Yes") { ........
Detect Word From A String
I called a query from database which will display a line of string e.g id1id2id3id4.... How do i detect if the string contain the word 'id4' for example. I'm using PHP 4.3.10
Extracting A Word From A String
I have been looking it up but cant come up with the code to extract a word from a string. example : "Hi There I am Kieron" I want to extract "Kieron" It doesn't matter really if the returned value equals what i am looking for a True or False would do. But it would be handy if i could.
Select Each Word Match On A String
here if we give the keyword as sony discman shock . the keyword is the product name. here i have to select datas. here sony discman is the product name of same. shock is another product. here i separate the string using explode function, what the thing three records are retrieved. ie.,the same record of product name is retrieved twice.how to solve this .
Count The # Of Word Occurance In A String
how do i get the number of occurence of the word [hello] from the following string and also i want to delete [hello] if its not closed by [/hello] : Quote: hi there [hello]this is my hello message[/hello][hello]this is another hello message[/hello]
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...
Shorten The Length Of A Word Within A String?
I have a table that is supposed to be only 400 pixels wide where I'm posting some articles that are pulled out of a mysql database using PHP. Sometimes the articles will contain a really long URL and it pushes the width of my table column so that it's larger than 400 pixels. Is there a way I can control the size of the URL or force it to break and continue on the next line?
Counting Occurrence Of A Word In A String :: Benchmarking Of PHP Functions
Today I was just thinking what are the possible ways to count the occurrence of a specific word inside a string. I found some possible ways finally and I just benchmarked them. Wanna see the result? - for sure you will find it interesting too. <? function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $str = "I have three PHP books, first one is 'PHP Tastes Good', next is 'PHP in your breakfast' and the last one is 'PHP Nightmare'"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { $cnt = count(split("PHP",$str))-1; } $end = microtime_float(); echo "Count by Split+Count took : ".($end-$start)." Seconds "; $start = microtime_float(); for ($i=0; $i<10000; $i++) { preg_match_all("/php/i",$str,$matches); $cnt = count($matches[0]); } $end = microtime_float(); echo "Count by Preg_Match+Count took : ".($end-$start)." Seconds"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { str_replace("PHP","PP",$str,$cnt); //echo $cnt; } $end = microtime_float(); echo "Count by str_replace took : ".($end-$start)." Seconds"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { str_ireplace("PHP","PP",$str,$cnt); //echo $cnt; } $end = microtime_float(); echo "Count By str_ireplace took : ".($end-$start)." Seconds"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { $cnt = count(explode("PHP",$str))-1; //echo $cnt; } $end = microtime_float(); echo "Count By Explode+Count took : ".($end-$start)." Seconds"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { $word_count = (array_count_values(str_word_count(strtolower($str),1))); ksort($word_count); $cnt = $word_count[`php']; } $end = microtime_float(); echo "Count By Array Functions took : ".($end-$start)." Seconds"; $start = microtime_float(); for ($i=0; $i<10000; $i++) { $cnt = count(preg_split("/PHP/i",$str))-1; } $end = microtime_float(); echo "Count By preg_split+Count took : ".($end-$start)." Seconds "; ?> And the result is First Run Count by Split+Count took : 0.43724584579468 Seconds Count by Preg_Match+Count took : 0.40852093696594 Seconds Count by str_replace took : 0.21707201004028 Seconds Count By str_ireplace took : 0.3386058807373 Seconds Count By Explode+Count took : 0.22872710227966 Seconds Count By Array Functions took : 1.6475439071655 Seconds Count By preg_split+Count took : 0.27543711662292 Seconds Second Run Count by Split+Count took : 0.40702390670776 Seconds Count by Preg_Match+Count took : 0.48372292518616 Seconds Count by str_replace took : 0.23599004745483 Seconds Count By str_ireplace took : 0.35310792922974 Seconds Count By Explode+Count took : 0.23321390151978 Seconds Count By Array Functions took : 0.98574304580688 Seconds Count By preg_split+Count took : 0.29601001739502 Seconds Third Run Count by Split+Count took : 0.41167497634888 Seconds Count by Preg_Match+Count took : 0.40696597099304 Seconds Count by str_replace took : 0.22049403190613 Seconds Count By str_ireplace took : 0.34511089324951 Seconds Count By Explode+Count took : 0.23123097419739 Seconds Count By Array Functions took : 0.98895502090454 Seconds Count By preg_split+Count took : 0.28659892082214 Seconds Fourth Run Count by Split+Count took : 0.4173800945282 Seconds Count by Preg_Match+Count took : 0.39977979660034 Seconds Count by str_replace took : 0.21876788139343 Seconds Count By str_ireplace took : 0.35455012321472 Seconds Count By Explode+Count took : 0.22984910011292 Seconds Count By Array Functions took : 0.9826991558075 Seconds Count By preg_split+Count took : 0.28095102310181 Seconds If you are interested to know the machine configuration, these tests ran on a Celeron 1.6GHz processor based laptop with 768 MB of RAM.
Help - Regexp For Extracting A String From A Larger String
I am developing a very basic CMS for a website I'm working on. One of the requirements is for the client to be able to post an image in their news posts, as well as links. I've got the links working (sort of, because I fear the way I have set it up may break images). Ideally I would like something like BBcode but can't wrap my head around regular expressions.
Parse Part Of String (mid String Function ?)
Can someone tell me how to parse part of a string? I can use the following: <?php $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo $text; ?> to get this result: "Your currently at /test.php " I just want to get "test.php " without the dash. I also need to parse out parts of other strings. I know how to use Mid(), Left(), and Right() in VB, but no clue for PHP.
Search A String And Return String Between Char?
I have a string like this; Full Name (Department) How can I split that string into seperate strings for Full Name and Department, so that everything before the () is the full name and everything between the () is the department?
Partially Replace A String With Data From The Same String...
I'm trying to write a script to help import some old HTML files as blog post for my website, these HTML files are 300-2000 lines long. I am currently using fgets() to read the files one line at a time, clean them and write them to the database in the appropriate format once the entire article is completed. My issue is many of the links included on these post no longer exist (some date into the '90s) and I want as part of my importing function to "fix" these links as so. Code:
Searching For A Recurring String In A String
I am teaching myself PHP. I have an HTML page with various products each with a specific reference in the form "Reference XXX". I would like to put an email link below each product with the product reference as part of the subject of the email link. What kind of procedure would you use? Could you please put me in the...
String To Filename-friendly-string
I've got a database whith titles of pages and I want to use them in my filenames (with Modrewrite). But, I have to use a function to convert them to filename-friendly-strings. e.g. title:"What's thŕt!?" should become something like: whats-that(.html) title:YOU & M€ should become you-m.html [ignoring strange characters] Someone who has got that function?
Converting A Hex String To A Binary String?
I have a situation where I have an 8-byte string which is represented as 16 hex digits. How do I convert a 16 hex digit string to an 8-byte binary string? I know I can use bin2hex to go from a binary string to a hex string (very useful)but is there a way to go the other direction? Right now I have a solution, which is to use a loop to go through the hex string one byte at a time, but that doesn't seem like a good way to do it. It seems like I should be able to use the pack() command, but I can't get it to work.
Replacing A String In A Larger String
i want to remove an email from a list of emails stored in a text file. using str_replace i can replace an email with nothing, but if the list is serated by commans, that would result in this: email@...,,email@...,email@... with no email between 2 commas. if i replace the email address with a comma on the end with nothing, it wouldn't work for the last one. if i replace the email address with a comma at the beginning, it wouldn't work for the first one. how can i avoid this or work around it?
Search String Delimited In Another String
I have a string (Website referrer). Example: http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N I need to extract the keywords searched (example in the above case: "MY STRING HERE"). I think I need the string between "q=" and the next appearing "&". How can I do this?
Matching String To String
Is there a way to search a string so that if there is a match it simply returns true? I have tried many functions and they seem to not work. What i am trying to do is if i have one string, say a url (e.g. http://www.games.com), and another string (e.g. games), how do i compare one to the other whether it is in the first string? And another thing, is there any way of finding the third occurence of a certain character in a string, something like the strchr() function?
How Do I See If One String Is Found Within Another String?
How do I see if one string is found within another string? or how many instances of one string, is found within another. ie. a="Sheree smells of poo" b="smells" I'd like a function that would return 1, (for true, or that the word smells, if found once) PHP is ace. There must be a simple way of doing this. I mean, its got loads of useless functions that noones ever going to use. Im sure if PHP has a built-in function to convert hebrew, then Im sure it can do this.
How To Insert A String Into Another String?
This one has me stumped... Let's say I have a string consisting of n words (where n > 0). I would like to insert string 'abcd' between the first and second characters of each word of the string. I could probably use a combination of explode, implode and substr, but I was wondering if there is a more elegant way of doing it using regular expressions?
Loosing It
two words from the form below and one simple query after, doesnt work, what to do to make it work <FORM ACTION=search.php METHOD=POST> <INPUT TYPE=TEXT NAME=search size=20> <INPUT TYPE=TEXT NAME=search1 size=20> <INPUT TYPE="submit" VALUE="Proceed query"> </FORM> <? //this one works fine: "select * from table_1 where dane like '%$search%'" //but i wanna the one below to work $query = "select * from table_1 where dane (like '%$search%') or dane (like '%search1%')"; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ //DOESNT WORK, WHY? $result = mysql_query($query); while($row = mysql_fetch_row($result)){ print_r($row[0]); echo '<br>' ....
Attaching/deleting Files
I'm trying to create a tree where you can access files from the tree. The files will NOT be stored in the database, but on the server. I have a web forum eg, where they store the title of the message in a separate table compared with the message which is another table. How do I store the files and show them on the tree, and how will the system know where to get the files from, if they're not in the database?
Mail() & Attaching Picture
How can i brows for picture on disk and then save it into array for mailing ? ------ "Half-brother in blood, full brother in heart will I be. Thou shalt lead and I will follow. May no new grief divide us."
Attaching An Image In A Php Newsletter.
This is my first post here so cheers everyone... I am pretty new to PHP so please forgive me if I get some of the lingo wrong or dont make sense Im working on a php code I found online. Im basically trying to send html emails (newsletters in a sense) to a group of signed up users. I have everything working but I want to be able to send images by PHP in the code below that creates the email and sends it out. Theres an html page that I fill out called mail_all.htm and it posts the info to mail_all.php (action="mail_all2.php") So I need help sending/attaching an image with the code below....
Loosing Session ID ?
I am having some problems with my sessions, it works ok with my cookies switched on, but I decided to test my scripts with them disabled and it doesn`t work and I cant figure out why. Here is my code:
Loosing Session
i am trying to implement ssl into my site. My ssl is setup under a different directory on the server (my host set up)So, i moved my three checkout pages and all of their include files to the new directory. I also changed all the links on the include files to the full path of my regular site for images ect. When i changed the link on the view cart page to the https:// address ..... it loses its session? When i leave the normal directory that the site is under and go to the https:// directory I have it will not pull up the $_SESSION['cart'] from the original directory.
Attaching A File To An Email Using Smtp
I'm searching for a php3 script that uses SMTP, allows me to attach file(s) and sends a simple plain text message to a user. I've tried other scripts and keep getting a server error on the line in my class file that sends the mail.
Session Loosing Vars
I'm using sessions to store some vars that are needed thruout my shopping-cart. sometimes the one or other var is lost. It doesn't happen often so we did a lot of testing and found that if the session looses a var it's not always the same var. We already downloaded opera and NS7 to see if it was a ie6 related problem. but it does not seam like its a browser related problem. What could it be? what can be done to fix this?
MySQL Loosing Data?
I am in desperate need of some help, recently data in our mySQL has been removing itself, rows themselves have not been delted buit just edit and row information has been wiped and left blank. We have checked the logs and it does not appear to be anyone doing it as there are no UPDATE/EDIT or DELETES being found in the logs. Any advice has this happened to anyone else before?
Session ID, 'loosing It' Between Pages?
I heard that there was a chance of 'loosing' a session ID between pages, (when the user clicks from one link to another). Is it really possible? Where could I find a definitive answer to that question? What browsers does that apply to? My database stores some information based on the session id, would there be another, (better), way of doing things? I know I could pass the Session ID from pages to pages but is there a better way?
Using '$' In Normal Text
// set the file name $filename = config.php"; // open the file $handle= fopen($filename,'a'); // create the string $string = "$dbhost="localhost"; $dbuser="user"; $dbpass="dbpass"; $dbname="dbname";" // write the string to the file handle fputs($handle, $string); // close the file fclose($handle); In the above script I am trying to generate a config.php file populated with db variables. Problem is, this part ($dbhost="localhost";
Creating Html Form And Attaching To Email
I have a template html form which contains for example name and address. When I am viewing this person I want to click a button which will fill in this form with the relevant name and address and then email it to an email address. I would prefer to attach this form in a pdf format. Is this possible?
Attaching Variables To A Database Positioning Calculation
I have 16 database fields: p1_id | p2_id | p3_id | p4_id | p5_id | p6_id | p7_id | p8_id pts_1 | pts_2 | pts_3 | pts_4 | pts_5 | pts_6 | pts_7 | pts_8 How it works is, the *_id fields contain the users ID number. The pts_* field contains a numeric score, the number after pts_ corrisponds to the user field (so the number in pts_5 belongs to p5_id). What I wish to do is determine 1st, 2nd, 3rd.... 8th positions, depending on the highest number (highest number = 1st, lowest = 8th) then give them a variable, which I need for later on in my script to send messages to each user telling them where they have come etc. As an example, this is how I've done it for just 2 users: <?php if($p1_pts > $p2_pts) { $1st = $p1_id; $2nd = $p2_id; } else { $1nd = $p2_id; $2nd = $p1_id; } ?> I need to do it for 2 users, 4, 6 and 8 users seperatly, the above is okay for 2 users but my mind is boggled for any more users!
PHP Not Compiling - I'm Loosing What's Left Of My Hair Over This!
I'm trying to compile PHP 4.4.1 on RH E3 ES. I need to enable zlib support but when I do PHP does not compile without errors. Here's what I did. make clean; ../configure --with-apxs2=/usr/sbin/apxs --with-mysql=/usr --with-config-file-path=/etc --enable-mbstring=all --with-zlib=/usr make; make: *** [libphp4.la] Error 1 If I run configure without --with-zlib=/usr it compiles just fine. So it is definitly zlib that's causing the error. What's weird though is that the error seems to come from mysql! The full error log is included below. I'm using MySQL 4.1 compiled from source. (It works fine.) /usr/lib/mysql/libz.a(adler32.o)(.text+0x0): In function `adler32': : multiple definition of `adler32' /usr/lib/mysql/libz.a(adler32.o)(.text+0x0): first defined here /usr/lib/mysql/libz.a(adler32.o)(.text+0x250): In function `adler32_combine': : multiple definition of `adler32_combine' /usr/lib/mysql/libz.a(adler32.o)(.text+0x250): first defined here /usr/lib/mysql/libz.a(compress.o)(.text+0x0): In function `compress2': : multiple definition of `compress2' /usr/lib/mysql/libz.a(compress.o)(.text+0x0): first defined here /usr/lib/mysql/libz.a(compress.o)(.text+0xb0): In function `compress': : multiple definition of `compress' /usr/lib/mysql/libz.a(compress.o)(.text+0xb0): first defined here /usr/lib/mysql/libz.a(compress.o)(.text+0xf0): In function `compressBound': : multiple definition of `compressBound' /usr/lib/mysql/libz.a(compress.o)(.text+0xf0): first defined here /usr/lib/mysql/libz.a(crc32.o)(.text+0x0): In function `get_crc_table': : multiple definition of `get_crc_table' /usr/lib/mysql/libz.a(crc32.o)(.text+0x0): first defined here /usr/lib/mysql/libz.a(crc32.o)(.text+0x10): In function `crc32': : multiple definition of `crc32' /usr/lib/mysql/libz.a(crc32.o)(.text+0x10): first defined here /usr/lib/mysql/libz.a(crc32.o)(.text+0x690): In function `crc32_combine': : multiple definition of `crc32_combine' /usr/lib/mysql/libz.a(crc32.o)(.text+0x690): first defined here /usr/lib/mysql/libz.a(deflate.o)(.rodata+0x0): multiple definition of `deflate_copyright' /usr/lib/mysql/libz.a(deflate.o)(.rodata+0x0): first defined here /usr/lib/mysql/libz.a(deflate.o)(.text+0x0): In function `deflateInit_': : multiple definition of `deflateInit_' /usr/lib/mysql/libz.a(deflate.o)(.text+0x0): first defined here /usr/lib/mysql/libz.a(deflate.o)(.text+0x50): In function `deflateInit2_': : multiple definition of `deflateInit2_' /usr/lib/mysql/libz.a(deflate.o)(.text+0x50): first defined here /usr/lib/mysql/libz.a(deflate.o)(.text+0x460): In function `deflateReset': : multiple definition of `deflateReset' /usr/lib/mysql/libz.a(deflate.o)(.text+0x460): first defined here /usr/lib/mysql/libz.a(deflate.o)(.text+0x1240): In function `deflateEnd': : multiple definition of `deflateEnd' /usr/lib/mysql/libz.a(deflate.o)(.text+0x1240): first defined here /usr/lib/mysql/libz.a(deflate.o)(.text+0x300): In function `deflateSetDictionary':
Loosing Date In HTML Form
as always i have a problem:-) i'm using HTML form. User is adding some date to this form and after that i'm generating plot. When plot is generated i can see en empty form and a plot. I want to see filled in form and a plot. don't know why i'm loosing all the data. when user adds data to the form i'm doing something like that: ...index.php?operation=added.. if operation=="added" then blablabla.. (of course its pseudocode).
Normal SQL Query Won't Work?!
The page "news.php" can have the following functionality: 1. news.php outputs a general "this is the newspage"-text (left column) and lists the 5 latest news (in the right column) 2. news.php?action=archive lists alla news i database (left column) and 5 latest (in right column) 3. news.php?action=item&newsID=n shows single news (bases on newsID) and 5 latest news i right column. Depending on which URL-string news.php gets, a different function gets executed. I know that the function (and the URL-stringJ works, since I did a simple test with "echo"-strings. However, when I add the code below, the page will not render properly. PHP Code:
Normal Error 404 Page
how would i go about getting the location of the current error 404 document for some directory with php? looking at the .htaccess file for a given directory isn't gonna do it because the error 404 document could have been assigned in some preceeding directory, or somewhere else...
String/xml
I have an xml output with tags like <sessionid>123</sessionid> <user>sands</sands> I could parse the output using expat to display it the way i want or as a string but what I need is to store the values separately in different variables like $id for sessionid, $user for user and so on.. to be manipulated later...
The URL String
Seeing as I cant get an array of text input values from the URL I receive, how do I get the full URL (so I can parse it myself) ? And where in the manual is the URL (the one received from a POST, not just any old URL) talked about?
String?
I have this kind of string: hucker23@hotmail.comam_marvin@yahoo.comhuckedge@yahoo.com how can i make this string be split into: hucker23@hotmail.com am_marvin@yahoo.com huckedge@yahoo.com and store in to an array: array[0] = hucker23@hotmail.com, array[1] = am_marvin@yahoo.com , array[2] = huckedge@yahoo.com
|