PHP - Splitting String Into Two Parts
I have a database full of strings which are basically URL's with ports, so by default my strings look like:
http://example.com:1234/ http://example2.com:3030/ http://example.com:9876/ http://example.com:5432/ What I am looking for is a way to separate the host from the post so the output would be something like: Host: example.com Port: 1234 Note: I once need to check one string at a time, so what I am after is something like: $string = "http://example.com:1234/"; And the result would be something like: $host (would be example.com without http://) $port (would be the port without ending /) Any help would be great Thanks for your time reasing this. Similar TutorialsOkay I need a little bit of help on this as strings constantly confuse me and reading tutorials actually got me a bit more loss then before. I have developed this mod that has become pretty popular and I'm debugging it. What I have are two variables. $username (The user's username, no html markup in it) $musername (The user's username, with html markup in it) So for example: $musername = <b><u>$username</u></b> The php code above would be the equivolant to what $musername is equal to. What I need to do is create an array or two variables, whatever is easier and grab all that html markup. The first variable would be all the html or anything really before the $username variable, and the other would take all of that html after the $username variable. I need to store those html markups in either two seperate variables or an array so i can call upon it later in the script. I need this to fix a bug issue. I have a string like this: Code: [Select] Something,Somthing Else,"keyword1,keyword2,keyword3",Yet another I need to split that string by the ,. However, I need the data that is n the quotes to remain as one even though it has commas because it is one item. I assume I need to use preg_split and have tried some code but none of it seems to work properly. If anyone has a better method or knows how I can split this up using preg_split the help is appreciated. The sample string is KmSO4 Every upper case alphabet should be identified and splitted until another upper case alphabet comes. the string should be splitted so that output array looks like this Array ( => Km [1] => S [2]=>O4 ) can any one help regarding this issue? Hello, I need to find the target html address within some raw html. I know it lies between Needle 1 and Needle 2 below. Needle 1: </span></a> <a href=" Needle 2: " rel="nofollow"><span class=pn><span class=np>Next »</span></span></a></div> Nornally I would just use the explode() function but my headache is that there are many instances of Needle 1 in the raw html code and I want my output array always have the same number of elements. However I do know that my target html address is directly after the last instance of Needle 1. How should I go about splitting the html code into an array that always has 3 elements? I'd like the first element to include code up to and including the last instance of Needle 2, the 2nd element to have the target html address, and the 3rd element to have Needle 2 and any following code. Thanks for any pointers (my main struggle is identifying the last instance of needle 1), Thanks, Stu Hi all,
I would like some input on database structure for a website that will sell car parts. Necessary fields a
Manufacturer
Part type (eg: exhaust, brakes, engine etc)
Part number
Description
Year & make of vehicle it fits (may need to be separate fields, I don't know, this is my main conundrum) **
Keep in mind, this is a basic example and purely hypothetical at this moment. I haven't done any coding yet.
My main roadblock at the moment is figuring out how to engineer part compatibility in conjunction with a search. Many parts fit many different vehicles. For example, part A123 could fit:
1999-2004 Jetta 2.0
1999-2004 Golf 2.0
1999-2004 Passat 1.9
In your opinion, what would be the most efficient way to store and retreive matching parts? Would I have each model as a separate row? i.e:
row 1: 2002-2004 Jetta ... part A123
row 2: 1999-2004 Golf... part A123
row 3: 1999-2004 Passat... part A123
Basically I would have many duplicate rows where only the year and vehicle model changes. This would definitely work, but would eventually lead to a very large and messy database.
There are already companies that offer a service such as this, but I am looking at looking to sell less products and secondly, in a different language. At the moment, I'm trying to figure out the best way that I could do it. Once I have an idea in mind, then I can decide whether I want to go ahead with that or use a pre-made commercial platform.
hello guys
i wand to split the 24h of a day to parts and select the time that i wand to start the 24h circle to count!
lets say
i give 2 int variables
$day_starts_to_count_from=00;
$split_day_to_parts=4;
so!
$hours_per_part = 24/$split_day_to_parts;
this gives me $hours_per_part = 6 (i split the 24h every 6hr)
how to know the part of my current hour?
lets say the system time is 15:35
how to find that im at the 3d part 12:00-18:00 if the 24h circle starts to count from 00:00
thanks in advance
so I have this code..........(not in brackets sorry) <table width="410" border="1" cellspacing="0" cellpadding="0"> <tr> <td width="339" bgcolor="#999999" scope="col">EVENTS</td> </tr> <tr> <td class="afasd"><?php echo date("F",strtotime("-0 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("-0 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> <tr> <td class="adfaf"><?php echo date("F",strtotime("+1 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("+1 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> <tr> <td class="jasdfjs"><?php echo date("F",strtotime("+2 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("+2 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> </table> so Only the third piece is working displaying correct things...........the other two don't display at all....... Hi I want to hide the login box's of my webpage once you login. I have thought of two ways of doing it but which one would you say is better practice? 1. use a PHP if statement to echo 'Display: none on css' - when viewing source code it still shows the form but not displayed on page itself 2. use a PHP if statement around the whole <form></form> so it physically doesnt write the html if already logged in? Or if anyone has a better way it would be appreciated if you would share it? Thanks in advance Heya guys! What's up? OK here's my problem: I got a variable, $var1, which is to have values like "groan,100,200,350,50" I need to know how to split this $var1 into $split1, $split2, $split3, $split4, $split5, where $split1 = "groan"; $split2 = "100"; $split3 = "200"; $split4 = "350"; $split5 = "50"; Thanks in advance people! P.S. In my case I am going to use some of the values for calculations. So I don't think that its easy with arrays, which are difficult for me to understand . P.S.S. When I am retrieving data from the database, many variables like $var1 that need to be split are being extracted. I hope that you understand. Thanks and Regards, Thauwa http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/get_hit_list?user_id=100000952273457&target_id=100000556624340&level=300&auth_key=cb07c7575b38df48d82dd53619385faa884db5a2 When going to this URL, it gives entries between <entry> and </entry>, what I am trying to do, is collect the <user_id> ONLY if the <amount> is over a certain value. Any ideas to how I could do this (I am a complete PHP noob). All help is appreciated Hi, I have had some developers do me some work but the person who did it has gone away for three weeks and it has stopped working. On my webpage https://bellevedeals.co.uk there's three flags (UK, US and EU) which when clicked are meant to load the appropriate menu's. This was working fine but for some reason is now not! I have created a page to prove that the cookies are outputting correctly, this is the case. When I click the US flag for example and load the page https://bellevedeals.co.uk/cookie.php it echos 'us'. Is anyone able to help me out? My header.php file is below. The code I believe is about line 256. Thank you so much in advance. Any questions or anything you need from me please let me know :) Matt <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" /> <?php elegant_description(); elegant_keywords(); elegant_canonical(); /** * Fires in the head, before {@see wp_head()} is called. This action can be used to * insert elements into the beginning of the head before any styles or scripts. * * @since 1.0 */ do_action( 'et_head_meta' ); $template_directory_uri = get_template_directory_uri(); ?> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <script type="text/javascript"> document.documentElement.className = 'js'; </script> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <?php $product_tour_enabled = et_builder_is_product_tour_enabled(); $page_container_style = $product_tour_enabled ? ' style="padding-top: 0px;"' : ''; ?> <div id="page-container"<?php echo et_core_intentionally_unescaped( $page_container_style, 'fixed_string' ); ?>> <?php if ( $product_tour_enabled || is_page_template( 'page-template-blank.php' ) ) { return; } $et_secondary_nav_items = et_divi_get_top_nav_items(); $et_phone_number = $et_secondary_nav_items->phone_number; $et_email = $et_secondary_nav_items->email; $et_contact_info_defined = $et_secondary_nav_items->contact_info_defined; $show_header_social_icons = $et_secondary_nav_items->show_header_social_icons; $et_secondary_nav = $et_secondary_nav_items->secondary_nav; $et_top_info_defined = $et_secondary_nav_items->top_info_defined; $et_slide_header = 'slide' === et_get_option( 'header_style', 'left' ) || 'fullscreen' === et_get_option( 'header_style', 'left' ) ? true : false; ?> <?php if ( $et_top_info_defined && ! $et_slide_header || is_customize_preview() ) : ?> <?php ob_start(); ?> <div id="top-header"<?php echo $et_top_info_defined ? '' : 'style="display: none;"'; ?>> <div class="container clearfix"> <?php if ( $et_contact_info_defined ) : ?> <div id="et-info"> <?php if ( '' !== ( $et_phone_number = et_get_option( 'phone_number' ) ) ) : ?> <span id="et-info-phone"><?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?></span> <?php endif; ?> <?php if ( '' !== ( $et_email = et_get_option( 'header_email' ) ) ) : ?> <a href="<?php echo esc_attr( 'mailto:' . $et_email ); ?>"><span id="et-info-email"><?php echo esc_html( $et_email ); ?></span></a> <?php endif; ?> <?php if ( true === $show_header_social_icons ) { get_template_part( 'includes/social_icons', 'header' ); } ?> </div> <!-- #et-info --> <?php endif; // true === $et_contact_info_defined ?> <div id="et-secondary-menu"> <?php if ( ! $et_contact_info_defined && true === $show_header_social_icons ) { get_template_part( 'includes/social_icons', 'header' ); } else if ( $et_contact_info_defined && true === $show_header_social_icons ) { ob_start(); get_template_part( 'includes/social_icons', 'header' ); $duplicate_social_icons = ob_get_contents(); ob_end_clean(); printf( '<div class="et_duplicate_social_icons"> %1$s </div>', et_core_esc_previously( $duplicate_social_icons ) ); } if ( '' !== $et_secondary_nav ) { echo et_core_esc_wp( $et_secondary_nav ); } et_show_cart_total(); ?> </div> <!-- #et-secondary-menu --> </div> <!-- .container --> </div> <!-- #top-header --> <?php $top_header = ob_get_clean(); /** * Filters the HTML output for the top header. * * @since 3.10 * * @param string $top_header */ echo et_core_intentionally_unescaped( apply_filters( 'et_html_top_header', $top_header ), 'html' ); ?> <?php endif; // true ==== $et_top_info_defined ?> <?php if ( $et_slide_header || is_customize_preview() ) : ?> <?php ob_start(); ?> <div class="et_slide_in_menu_container"> <?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) || is_customize_preview() ) { ?> <span class="mobile_menu_bar et_toggle_fullscreen_menu"></span> <?php } ?> <?php if ( $et_contact_info_defined || true === $show_header_social_icons || false !== et_get_option( 'show_search_icon', true ) || class_exists( 'woocommerce' ) || is_customize_preview() ) { ?> <div class="et_slide_menu_top"> <?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) ) { ?> <div class="et_pb_top_menu_inner"> <?php } ?> <?php } if ( true === $show_header_social_icons ) { get_template_part( 'includes/social_icons', 'header' ); } et_show_cart_total(); ?> <?php if ( false !== et_get_option( 'show_search_icon', true ) || is_customize_preview() ) : ?> <?php if ( 'fullscreen' !== et_get_option( 'header_style', 'left' ) ) { ?> <div class="clear"></div> <?php } ?> <form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <?php printf( '<input type="search" class="et-search-field" placeholder="%1$s" value="%2$s" name="s" title="%3$s" />', esc_attr__( 'Search …', 'Divi' ), get_search_query(), esc_attr__( 'Search for:', 'Divi' ) ); ?> <button type="submit" id="searchsubmit_header"></button> </form> <?php endif; // true === et_get_option( 'show_search_icon', false ) ?> <?php if ( $et_contact_info_defined ) : ?> <div id="et-info"> <?php if ( '' !== ( $et_phone_number = et_get_option( 'phone_number' ) ) ) : ?> <span id="et-info-phone"><?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?></span> <?php endif; ?> <?php if ( '' !== ( $et_email = et_get_option( 'header_email' ) ) ) : ?> <a href="<?php echo esc_attr( 'mailto:' . $et_email ); ?>"><span id="et-info-email"><?php echo esc_html( $et_email ); ?></span></a> <?php endif; ?> </div> <!-- #et-info --> <?php endif; // true === $et_contact_info_defined ?> <?php if ( $et_contact_info_defined || true === $show_header_social_icons || false !== et_get_option( 'show_search_icon', true ) || class_exists( 'woocommerce' ) || is_customize_preview() ) { ?> <?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) ) { ?> </div> <!-- .et_pb_top_menu_inner --> <?php } ?> </div> <!-- .et_slide_menu_top --> <?php } ?> <div class="et_pb_fullscreen_nav_container"> <?php $slide_nav = ''; $slide_menu_class = 'et_mobile_menu'; $slide_nav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) ); $slide_nav .= wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) ); ?> <ul id="mobile_menu_slide" class="<?php echo esc_attr( $slide_menu_class ); ?>"> <?php if ( '' === $slide_nav ) : ?> <?php if ( 'on' === et_get_option( 'divi_home_link' ) ) { ?> <li <?php if ( is_home() ) echo( 'class="current_page_item"' ); ?>><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php esc_html_e( 'Home', 'Divi' ); ?></a></li> <?php }; ?> <?php show_page_menu( $slide_menu_class, false, false ); ?> <?php show_categories_menu( $slide_menu_class, false ); ?> <?php else : echo et_core_esc_wp( $slide_nav ) ; endif; ?> </ul> </div> </div> <?php $slide_header = ob_get_clean(); /** * Filters the HTML output for the slide header. * * @since 3.10 * * @param string $top_header */ echo et_core_intentionally_unescaped( apply_filters( 'et_html_slide_header', $slide_header ), 'html' ); ?> <?php endif; // true ==== $et_slide_header ?> <?php ob_start(); ?> <header id="main-header" data-height-onload="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>"> <div class="container clearfix et_menu_container"> <?php $logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && ! empty( $user_logo ) ? $user_logo : $template_directory_uri . '/images/logo.png'; ob_start(); ?> <div class="logo_container"> <span class="logo_helper"></span> <a href="<?php echo esc_url( home_url( '/' ) ); ?>"> <img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" /> </a> </div> <?php $logo_container = ob_get_clean(); /** * Filters the HTML output for the logo container. * * @since 3.10 * * @param string $logo_container */ echo et_core_intentionally_unescaped( apply_filters( 'et_html_logo_container', $logo_container ), 'html' ); ?> <div id="et-top-navigation" data-height="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>" data-fixed-height="<?php echo esc_attr( et_get_option( 'minimized_menu_height', '40' ) ); ?>"> <?php if ( ! $et_slide_header || is_customize_preview() ) : ?> <nav id="top-menu-nav"> <?php $menuClass = 'nav'; if ( 'on' === et_get_option( 'divi_disable_toptier' ) ) $menuClass .= ' et_disable_top_tier'; $primaryNav = ''; if($_COOKIE['storeselector']=='uk') { $primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); } else if($_COOKIE['storeselector']=='us'){ $primaryNav = wp_nav_menu( array( 'theme_location' => 'us-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); } else if($_COOKIE['storeselector']=='eu'){ $primaryNav = wp_nav_menu( array( 'theme_location' => 'eu-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); } else{ $primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); } if ( empty( $primaryNav ) ) : ?> <ul id="top-menu" class="trans <?php echo esc_attr( $menuClass ); ?>"> <?php if ( 'on' === et_get_option( 'divi_home_link' ) ) { ?> <li <?php if ( is_home() ) echo( 'class="current_page_item"' ); ?>><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php esc_html_e( 'Home', 'Divi' ); ?></a></li> <?php }; ?> <?php show_page_menu( $menuClass, false, false ); ?> <?php show_categories_menu( $menuClass, false ); ?> <li class="menu-item"><div class="langselectorr"> <img src="<?php echo get_option( 'my_layout_option9', true );?>" class="lanchooserico uslang" title="USA"> <img src="<?php echo get_option( 'my_layout_option8', true );?>" class="lanchooserico uklang" title="United Kingdom"> <img src="<?php echo get_option( 'my_layout_option10', true );?>" class="lanchooserico eulang" title="Europe"> </div></li> </ul> <?php else : echo et_core_esc_wp( $primaryNav ); endif; ?> </nav> <?php endif; ?> <?php if ( ! $et_top_info_defined && ( ! $et_slide_header || is_customize_preview() ) ) { //et_show_cart_total( array('no_text' => true,) ); } ?> <?php if ( $et_slide_header || is_customize_preview() ) : ?> <!--<span class="mobile_menu_bar et_pb_header_toggle et_toggle_<?php echo esc_attr( et_get_option( 'header_style', 'left' ) ); ?>_menu"></span>--> <?php endif; ?> <?php if ( ( false !== et_get_option( 'show_search_icon', true ) && ! $et_slide_header ) || is_customize_preview() ) : ?> <div id="et_top_search"> <div class="langselectorr"> <img src="<?php echo get_option( 'my_layout_option9', true );?>" class="lanchooserico uslang" title="USA"> <img src="<?php echo get_option( 'my_layout_option8', true );?>" class="lanchooserico uklang" title="United Kingdom"> <img src="<?php echo get_option( 'my_layout_option10', true );?>" class="lanchooserico eulang" title="Europe"> </div> <!--<span id="et_search_icon"></span>--> </div> <?php endif; // true === et_get_option( 'show_search_icon', false ) ?> <?php /** * Fires at the end of the 'et-top-navigation' element, just before its closing tag. * * @since 1.0 */ do_action( 'et_header_top' ); ?> <div class="langselectorr"> <img src="<?php echo get_option( 'my_layout_option9', true );?>" class="lanchooserico uslang" title="USA"> <img src="<?php echo get_option( 'my_layout_option8', true );?>" class="lanchooserico uklang" title="United Kingdom"> <img src="<?php echo get_option( 'my_layout_option10', true );?>" class="lanchooserico eulang" title="Europe"> </div> </div> <!-- #et-top-navigation --> </div> <!-- .container --> <div class="et_search_outer"> <div class="container et_search_form_container"> <form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <?php printf( '<input type="search" class="et-search-field" placeholder="%1$s" value="%2$s" name="s" title="%3$s" />', esc_attr__( 'Search …', 'Divi' ), get_search_query(), esc_attr__( 'Search for:', 'Divi' ) ); ?> </form> <span class="et_close_search_field"></span> </div> </div> </header> <!-- #main-header --> <?php $main_header = ob_get_clean(); /** * Filters the HTML output for the main header. * * @since 3.10 * * @param string $main_header */ echo et_core_intentionally_unescaped( apply_filters( 'et_html_main_header', $main_header ), 'html' ); ?> <div id="et-main-area"> <?php /** * Fires after the header, before the main content is output. * * @since 3.10 */ do_action( 'et_before_main_content' ); ?> <style type="text/css"> @media only screen and (min-width:981px) { .et_header_style_left #et-top-navigation, .et_header_style_split #et-top-navigation { padding:39px 0 0 0; } .lanchooserico {cursor: pointer;float: left;margin-right: 4px;width: 20px;} .langselectorr{width:85px;} .lanchooserico.active {background-color: #f8bd18;opacity: 0.8;border: 1px solid #f8bd18;} .et_search_outer{display: none !important;opacity: 0;} </style> <script type="text/javascript"> jQuery('.uslang').on('click',function(){ setCookie('storeselector','us',365); jQuery('.uslang').addClass('active'); jQuery('.uklang').removeClass('active'); jQuery('.eulang').removeClass('active'); window.location.href = "https://bellevedeals.co.uk/"; }); jQuery('.uklang').on('click',function(){ setCookie('storeselector','uk',365); jQuery('.uklang').addClass('active'); jQuery('.uslang').removeClass('active'); jQuery('.eulang').removeClass('active'); window.location.href = "https://bellevedeals.co.uk/"; }); jQuery('.eulang').on('click',function(){ setCookie('storeselector','eu',365); jQuery('.eulang').addClass('active'); jQuery('.uslang').removeClass('active'); jQuery('.uklang').removeClass('active'); window.location.href = "https://bellevedeals.co.uk/"; }); jQuery(document).ready(function(){ if(getCookie('storeselector')=='us') { jQuery('.uslang').addClass('active'); jQuery('.uklang').removeClass('active'); jQuery('.eulang').removeClass('active'); } else if(getCookie('storeselector')=='uk') { jQuery('.uklang').addClass('active'); jQuery('.uslang').removeClass('active'); jQuery('.eulang').removeClass('active'); } else if(getCookie('storeselector')=='eu') { jQuery('.eulang').addClass('active'); jQuery('.uslang').removeClass('active'); jQuery('.uklang').removeClass('active'); } else { jQuery('.uklang').addClass('active'); jQuery('.uslang').removeClass('active'); jQuery('.eulang').removeClass('active'); } }); function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } </script> <?php setcookie("myCookie", '879', time() + 3600); ?>
I have an image which is a complete image that has 4 titles(aquatic weeds,green algae,water quality,bottom muck) Can i write a code somehow that when i hover over those images or title i can link it to different hyperlinks? Is this possible? Could the following code be replaced with one .txt consisting of two digits? Code: [Select] $myFile = "offerrotation.txt"; $myFile2 = "lprotation.txt"; $fh = @fopen($myFile, 'r'); $offerNumber = @fread($fh, 5); @fclose($fh); $fh = @fopen($myFile2, 'r'); $lpNumber = @fread($fh, 5); @fclose($fh); Many thanks Hi, Everyone! I have an issue and I'm not even sure if it can be done with PHP, but even this info would help me (to stop looking for an answer). I need to populate a (MySQL) database with stuff which is now written in a (HTML formatted) file. Here are my options: 1. Copy/paste each single field via PHPMyAdmin . 2. Write a little script to extract the necessary parts of text from these files to create a CSV-like content which I would then easily INSERT into the db. Example The files look like this: Code: [Select] <!-- SEPARATOR (same throughout the file(s) --> <tr><td> <div style="something"><img src="img/what_i_need_to_extract_1.png"></div> </td><td> <div style="something else"><b>What I need to extract 2</b></div> <div style="something else">What I need to extract 3</div> </td></tr> <!-- SEPARATOR (same throughout the file(s) --> etc ... and it goes like... 100 times in each file in the same standard pattern with the "What I need to extract" parts being completely different each time. Since it's possible to tell when each part required for extraction begins and ends, I would expect the script to look for these key-points (according to the example, it would be: img/ to "></d then "><b> to </b>< and else"> to </div>) and return a result like this (acc. to the example): ('what_i_need_to_extract_1.png', 'What I need to extract 2', 'What I need to extract 3'), (and so on...). Is it possible? Is there a function/option/way to look for a start/end-point like this and fetch the part between these two set points? If so - how? Any help would be appreciated, I'm not expecting a full code, obviously, just a point to the right direction or where to look at would be nice. Thanks in advance. I have a text field that contains the following (example text used): 1 2 3 4 5 6 As you can see the first few are split by a single space, with the last few numbers split by a double space. My aim is to put each of these numbers into a table in a MYSQL database. But I'm having trouble breaking them up. I could use some suggestions on how to break up my HTML and PHP. Currently I have a file called "payment_form.php" It looks like this... Code: [Select] <body> <?php // HANDLE FORM. if (isset($_POST['submitted'])){ // Handle Form. // Determine if any errors. if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... // Do not return to Payment Form!!! exit(); } } ?> <!-- HTML PAYMENT FORM --> <form id="payment" action="" method="post"> <fieldset> <legend>Billing Details</legend> <ol> <!-- First Name --> <li> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" class="text" type="text" maxlength="20" value="<?php echo $firstName; ?>" /> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> </li> I would like to keep the Form Validation PHP in the same file as the HTML Form so the user isn't ping-ponged between two pages if they make data entry errors. However, I am thinking it would be better to break out the Payment Processing PHP and place that in a different file. How should I do that? Maybe I could add a Redirect after this code... Code: [Select] if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... Suggestions welcome!! Thanks, Debbie Hi guys Say for example I have a text field with value 20/10/2011 how do I define it so that $x=20, $y=10 and $z=2011 so that I have three variables Thanks Hi Guys, does anyone know how split a text into groups depending on how many words are in the text e.g $text = "If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. "; I want a maximium of 5 words in each group, so the above text will be split as such $text1 = 'If you are new to'; $text2 = 'PHP and want to get'; $text3 = 'some idea of how it '; $text4 = 'works, try the introductory tutorial.'; But if I want a maximium of 10 words in each group, so the above text will then be split like this $text1 = 'If you are new to PHP and want to get'; $text2 = 'some idea of how it works, try the introductory tutorial.'; $text3 = ''; $text4 = ''; Is this possible? Please any help will be much appreciated thanks |