hiya guys,
Before asking question let me tell you i am really bad at regular expressions (REGEX) :(
Well to start with, i want to get the value inside a div with a particular id.
An example can be
[HTML]<div id="static">
This is the content i want to fetch, When i have this whole file in the string format which i got it from file_get_contents
</div>
[/HTML]
I hope i made my question clear, please let me know how can i do that ?
Thanks :)
Cheers !!
11 11092
Would
[php]
preg_match('/<div id=\"".$id."\">(.*?)</div>/', $string, $matches);
[/php]
Work?
Would
[php]
preg_match('/<div id=\"".$id."\">(.*?)</div>/', $string, $matches);
[/php]
Work?
really thanks a lot for quick response, but can i do it without regex ??
i mean isnt there any way out ??
though i reckon,this is the best/only way :)
cheers !! thanks again
well writing this would give me error,
[PHP]preg_match('/<div id=\"normal\">(.*?)</div>/', $getWholePage, $matches);
Warning: preg_match() [function.preg-match]: Unknown modifier 'd' in D:\xamp\htdocs\cut\index.php on line 14
[/PHP]
well writing this would give me error,
[PHP]preg_match('/<div id=\"normal\">(.*?)</div>/', $getWholePage, $matches);
Warning: preg_match() [function.preg-match]: Unknown modifier 'd' in D:\xamp\htdocs\cut\index.php on line 14
[/PHP]
preg_match('/<div id=\"normal\">(.*?)</div>/', $getWholePage, $matches);
The delimiter is a forward slash, so you need to escape it in the closing div tag.
preg_match('/<div id=\"normal\">(.*?)<\/div>/', $getWholePage, $matches);
Although this is the PHP forum, so my post does not really belong here, I'd like you to consider a JavaScript solution (since you do not want to use a regexp). See this sample - <div id="static">
-
This is the content i want to fetch, When i have this whole file in the string format which i got it from file_get_contents
-
</div>
-
<script type="text/javascript">
-
if (document.getElementById("static").firstChild.nodeName=="#text")
-
alert ('The div text is: '+document.getElementById("static").firstChild.nodeValue);
-
</script>
Ronald
Although this is the PHP forum, so my post does not really belong here, I'd like you to consider a JavaScript solution (since you do not want to use a regexp). See this sample - <div id="static">
-
This is the content i want to fetch, When i have this whole file in the string format which i got it from file_get_contents
-
</div>
-
<script type="text/javascript">
-
if (document.getElementById("static").firstChild.nodeName=="#text")
-
alert ('The div text is: '+document.getElementById("static").firstChild.nodeValue);
-
</script>
Ronald
but will this script work for a string ??
As i mentioned i am getting a file contents using PHP function..
I guess JS works on browser and when the current page is loaded..
Say if i am on page X i want to get the contents of a div which is stored in varibale $str.
Is that possible using JS ??
I really don't know what you want to achieve or why. But assuming the complete div is in a PHP variable $str and you wanted to get only the 'between' div's text from that php variable using JS. In order to prevent passing the PHP variable to JS, I would show the div (from the variable) within another div with visibility=hidden and run the JS. Like this[php]<?php
$str='<div id="static">This is the content i want to fetch, When i have this whole file in the string format which i got it from file_get_contents</div>';
?>
<div id="myId" style="visibility: hidden;">
<?php
echo $str;
?>
</div>
<script type="text/javascript">
if (document.getElementById("static").firstChild.node Name=="#text")
alert ('The div text is: '+document.getElementById("static").firstChild.nod eValue);
</script>[/php]But when the above is not what you are looking for then I don't understand your problem and, in that case, please elaborate a bit more.
Ronald
I really don't know what you want to achieve or why. But assuming the complete div is in a PHP variable $str and you wanted to get only the 'between' div's text from that php variable using JS. In order to prevent passing the PHP variable to JS, I would show the div (from the variable) within another div with visibility=hidden and run the JS. Like this[php]<?php
$str='<div id="static">This is the content i want to fetch, When i have this whole file in the string format which i got it from file_get_contents</div>';
?>
But when the above is not what you are looking for then I don't understand your problem and, in that case, please elaborate a bit more.
Ronald
Wow,
thanks, i guess this should work. I will check when i get back home..
you are always a life saver bro ;)
thx
cheers !!
Realin !
So you mean I understood your question.problem? If that is the case I hope that solution works for you. I'm always in for a coding challenge.
Ronald
yup ronanld,
the solution worked for me, i used more smarter jquery :) but the idea was yours to display the string, how can i miss that :p
hehehe.. anyways thanks a lot :)
Don't blame yourself for missing that. It works, that's all you need. See you around.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does...
|
by: Ian Davies |
last post by:
Hello
In a php file I have a drop down list with index numbers in whos default
value is feed into an sql query that filters records from my database and
displays them in an html table. Trouble...
|
by: |
last post by:
Is there any sample about getting the results from executing an exe using
C#?
Thanks for answering.
|
by: Tina |
last post by:
I'm trying to get started with Atlas and associated necessary javascript at
the same time. I started out at
http://atlas.asp.net/walkthroughs/gettingstarted/basic.net where they have
an...
|
by: ced69 |
last post by:
having trouble getting marquee to work get object required errors
tring t <title>This Month at the Chamberlain Civic Center</title>
<link href="styles.css" rel="stylesheet"...
|
by: raghuvendra |
last post by:
Hi
I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button.
All these are aligned in a row. And Each Category Name has its corresponding Category...
|
by: N00b13 |
last post by:
I have a great JS menu but I have to update every page each time I want to change a link. Is there a way to store my links in a file and call it so i only change that file? (what I have tried so far...
|
by: vikas251074 |
last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
|
by: vikas251074 |
last post by:
I am getting error above in following code since few days giving tension day and night.
How can I solve this? I am facing since Oct.25. in line no. 362
After doing a lot of homework, I am...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |