PHP - Only The First Part Of A String Comes Through
I'm using PHP to get a list of names from a mysql database, which then produces a drop down list for the user to select an option and then progress to the next page where the selection is displayed with other stuff. My problem is that my drop down list works fine, but when the user goes to the next page only the first part of the string is displayed, ie if the string is Fred Bloggs, only Fred is shown. I can get it to work by adding ' ' around the string name in the option section, but this shows 'Fred Bloggs' in the drop down list which isn't very pretty.
I haven't got the actual code to hand at the moment, but any ideas on where I'm going wrong? Cheers Similar Tutorialshi php freaks, have link in a menu that looks like the following. I have been able search the string using strpos($lines[$i],'title='). What I want to know is how do I get the school summary into a variable. Code: [Select] <li><a href="../index.php" title="school summary">Summary</a></li> any help would be great Hi i need help with some string manipulation and extraction.. http://www.test.com/forums/attachment/f39/745d1267084199-official-ar-m16-m4-picture-thread-dsc00005.jpg I need to extract an id from the above path dynamically. I need to extract the digits before the alphabet d after the second last path f39/ In the above case the number extracted would be 745. Can someone please help me out with it? Hi - newbie to php - I need to search a string and possibly replace part of it. This is how I would do it in perl: Code: [Select] if ($homepage) { if ($homepage !~ /http/i) { $homepage = "http:\/\/" . $homepage; } } I have a homepage field in the database but sometimes people put the http in, and sometimes they leave it out. In perl I can figure it out and format accordingly but it doesn't work in PHP. I'm not sure if the first line even works in PHP. Maybe if to say something like: if $homepage is not equal to nothing. I'm not sure. Any help would be appreciated. Thanks. Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. Hello guys, I want to remove part of a string and convert it to a var instead of echoing it out.. How would I do it.. $string = "temp_photo/testing.jpg"; I want to remove temp_photo so the out put should be $filename2 = testing.jpg Please advise.. Thanks, Dan I have string like this (without the spaces) [ QUOTE="Adrock"]This is a test message[/QUOTE ] How do i get just what is between the double quotes taking into account in the message there could be double quotes? I've tried this but it doesn't echo anything unless i put the square brackets in but i want the username $origauth = html_entity_decode($message); $b = substr($origauth, strpos($origauth, '&#034') + 1); $c = substr($b, 0, strpos($b, '&#034')); echo $c; I have the following DOM document ( this is a sample document and is "as is", it's 100% intended to look like this ): <everything> <cars> <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it </cars> <houses> <house>Big Red House</house> </houses> </everything> This is all being put into a $newdoc = new DOMDocument(); $myString = ................. ; // ????? I only want the content of <cars> in here, and without having the <cars> tag How can I make this "$myString look like the following: $myString = ' <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it '; Preferably without any looping. Hey there. Thinking this should be an easy one but I can only seem to find info on the string replace function. What I'm trying to do is strip everything after the @ from an email variable. So for example $mail variable comes in as me@gmail.com How would I strip the variable to only contain me and remove the @gmail.com I'll keep searching for the answer myself but if anyone can throw me a bone it's be appreciated. Cheers Hey guys! I found a flush function and it seems to be working well, but sometimes it will cut off characters. It's very strange. Here's my flush function: function out($str) { echo $str."<br />\n"; vbflush(); } function vbflush() { if (ob_get_length()){ @ob_flush(); @flush(); @ob_end_flush(); } @ob_start(); }And I'm calling it like this:out('Waiting 30 seconds until execution');And this is my output: Code: [Select] Waiting 30 seconds until executioAnyone know why? Hey guys I'm having an issue trying to get my PHP to display the first url of my exploded string and non of the others.
The SQL table column contains strings like this:
http://www.imgurl.com/image.jpg,http://www.imgurl.com/image2.jpg,http://www.imgurl.com/image3.jpg,http://www.imgurl.com/image4.jpg Hello, I have several job categories on a recruitment website: $job_category[0]="accountant"; $job_category[1]="php programming"; $job_category[2]="baseball"; these job categories are contained within the urls imediately after the recruiting company's name and before the word "jobs", so we could have the following urls: www.url.com/company_name_accountant_jobs www.url.com/another_company_name_baseball_jobs www.url.com/yet_another_company_name_php programming_jobs Using the array $job_categories and the page path after the foward slash (e.g. yet_another_company_name_php programming_jobs) please could you tell me how to strip out the job category and the company name? (I'll extract the page path using a mod_rewrite) Thanks Stu Hi all, first time here as I am a bit stuck. I am by no means a programmer and I was hoping that someone out there may have a simple solution to my problem?... So here goes" I have a voucher/offers site up-and-running. The site content is generated from an external feed. I want to create other sites and I want to track what sales/clicks have come from where. An example of the feed: (http://www.awin1.com/awclick.php?mid=251&id=28971&clickref=[URL_REFERENCE]&p=http://www.247electrical.co.uk) As you will see, I have [URL_REFERENCE] in each link. I want to automatically change that part of the string in the database. Does anyone have any thoughts? Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> </td></tr><tr><td colspan="2" class="para" style="padding-left:10px;"> <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> </td></tr> I have the above snippet.. The first php statement, basically grasp the first 701 characters with the closet next stop "." character and out puts it. then out puts the HTML tags I have a problem with the second statement. I want to output anything after what has been outputted by: Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> So need the correct syntax for Code: [Select] <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> Currently it breaks at exactly the 701 character, want it to continue from the sentence the first code ended in. My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! |