Jump to content


  • Posts

  • Joined

  • Last visited


Everything posted by etrader

  1. The file contains lines with TITLE, and HEADER, and some keywords I am thinking of $array=array('file.txt'); foreach ($array as $line) { $parse=explode(",", $parse); $title=$parse[0]; $header=$parse[1]; $key=???? } The problem is that I cannot take a random from $parse[2] to $parse['last']
  2. I want to create an array from a file with this structure TITLE1, HEADER1, key11, key12, key13, key14 TITLE2, HEADER2, key21, key22, key23, key24 . . . How I can get a foreach with these elements: $title="TITLE" $header="HEADER" $key="(one random key)" If needed, I can change the file structure too.
  3. I think you mean $urlParts[0]. But even in the case, the problem appears when we are on the main domain. For example.com; it will return "example"
  4. I introduce if condition when a string is empty as if (empty($string)) { How I can add the condition for a certain value too. If empty or equal to "word1".
  5. What is the easiest way to get the value of subdomain. For example, when browsing word1.example.com; how to get it (like $_GET['q']) to put "word1" into an string.
  6. I have loaded two similar xml files by simplexml_load_file, and I want to merge them. They have similar structure and I want to put them into a single xml. As a matter of fact, I have parse two similar xml files with foreach, and now I want to put them together and use one foreach for the merged xml. I hope to find a function like array_merge()
  7. I have two questions: 1. Is it the best way to get the domain of a url by parse_url? or preg_match or str_replace can be better alternatives? 2. What is the best way to remove www from the domains? Note that the domain name itself may contain www too (like www.1www.com) Thank for your attention
  8. I have two array, how I can have if else to check if both array1 and array2 are empty? if (empty both arrays) { } else { even if one of them are not empty }
  9. I want to merge some arrays as $mixing = array_merge($mixedresult1, $mixedresult2, $mixedresult3); but the arrays can be empty sometimes. In this case, I will get an error for the empty array as PHP Warning: array_merge() [<a href='function.array-merge'>function.array-merge</a>]: Argument #1 is not an array How I can avoid this error by omitting empty arrays?
  10. Seems to be a subtle solution, but the output in all cases is "no"
  11. Thank fella, How to avoid foreach by defining a string ($var) containing the words as $var='word1|word2|word3' to check if any value matches.
  12. I want to check if a string has any of words listed in array; $array=array('word1', 'word2', 'word3'); $string="This is a sentence containing word2"; Now I want to make an 'if else' to check if the string contains any of the words listed in the array. Thanks
  13. I want to run a php file which contains a long process and takes time. If I simply run the file on browsers, the process will be interrupted by any perturbation in the internet connection or closing the browser. How I can force the php process to continue running without connection to my local PC (server side controlling)? I am looking for something like what cron job does (but only one time, not periodically).
  14. I send email via simple code of $message="$description"; $to="email@googlemail.com"; $from="email@hotmail.com"; $headers="From:" . $from; mail($to,$title,$message,$headers); I am looking for the simplest way to add attachment to the email. The instructions given on the internet make the case complicated. I just need to make it simply. Thanks
  15. oh thanks, I did not think of the powerfulness of array Thanks again!
  16. I need a simple code like $test1="1"; $test2="2"; $test=$test1|$test2; echo $test; to randomly catch the value of strings $test1 or $test2; as each time running the code, echo shows randomly one of the strings. Could you please guide what the third line should be ?
  17. I use this code to catch a list between <ul> tag: preg_match('/<ul style=\"list\" >(.*)?<\/ul>/siU', $html, $match); but my problem is that the preg_match continues until the last </ul>. How I can limit the preg_match just until the next </ul>
  18. Part of my page is taken from external webpages by preg_match. Since It is a partial section, it contains incomplete tags such as <div>, <span>, etc. Thus, they mix up with my entire page and my </div>, </span> are used for the incomplete tags in the borrowed section. How I can end such tags? or separate this section from the main codes (I mean having an isolated section)?
  19. That's exactly that way I hoped to find Thanks so much
  20. I want to echo the last two (or at least the last) string of an array. What is the simplest way to do so ?
  21. Image some string which get content from an external webpage and displaying them with echo. Now, there are lots of useless whitespace between the codes. e.g. $string1=file_get_content(http://external.com); $string2 ='<some code> </div>' echo $string1; echo $string2;
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.