Author Topic: [SOLVED] substring help!!!  (Read 675 times)

0 Members and 1 Guest are viewing this topic.

Offline ilkernycTopic starter

  • Irregular
    • View Profile
[SOLVED] substring help!!!
« on: November 02, 2007, 11:05:29 PM »
Hi,

i want to get the url string out of the href. For example this comes back from the database:

a href="http://something.com" target="_blank" /a

i want to get the substring "http://something.com" How do i do it?

Thank you so much for your helps

Note: Url's are in different lenghts in the database
« Last Edit: November 02, 2007, 11:07:22 PM by ilkernyc »

Offline MadTechie

  • PHPFreaks Recommended
  • Freak!
  • *
  • Gender: Male
  • I try to F1
    • View Profile
Re: substring help!!!
« Reply #1 on: November 02, 2007, 11:11:38 PM »
better to use RegEx..
see Regex Section

example code
Code: [Select]
<?php
$html 
'<a href="http://something.com" target="_blank">Test </a>';
if (
preg_match('/href="([^"]*)"/i'$html $regs))
{
$result $regs[1];
} else {
$result "No URL Found";
}
echo 
$result ;
?>
Computers are good at following instructions, but not at reading your mind.
After all, why would you insert your penis into a hole for no reason whatsoever?

I dunno about that.  A regular expression has a 0% chance of touching my penis.

the code is professionally made up but not working

Remember to Click Solved, how to ask questions - the smart way

Offline ilkernycTopic starter

  • Irregular
    • View Profile
Re: [SOLVED] substring help!!!
« Reply #2 on: November 04, 2007, 01:44:39 AM »
thanks a lot!

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.